npm workspaces, NodeNext for server
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { Request, Response } from "express";
|
||||
import type { User } from "@types";
|
||||
import type { User } from "@chessu/types";
|
||||
import xss from "xss";
|
||||
|
||||
export const getCurrentSession = async (req: Request, res: Response) => {
|
||||
|
||||
@@ -1,30 +1,28 @@
|
||||
import type { Request, Response } from "express";
|
||||
import { activeGames } from "../db/models/game.model";
|
||||
import type { Game, User } from "@types";
|
||||
import { activeGames } from "../db/models/game.model.js";
|
||||
import type { Game, User } from "@chessu/types";
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
export const getActiveGames = async (req: Request, res: Response) => {
|
||||
try {
|
||||
//if (!req.query || !req.query.code) {
|
||||
res.status(200).json(activeGames);
|
||||
res.status(200).json(activeGames.filter((g) => !g.unlisted));
|
||||
//}
|
||||
|
||||
/*
|
||||
// todo: if code query is URL, convert to code (or do it on client side?)
|
||||
const code =
|
||||
(req.query.code as string).startsWith("http") ||
|
||||
(req.query.code as string).startsWith("ches.su")
|
||||
? path.posix.basename(url.parse(req.query.code as string).pathname as string)
|
||||
: req.query.code;
|
||||
// const code =
|
||||
// (req.query.code as string).startsWith("http") ||
|
||||
// (req.query.code as string).startsWith("ches.su")
|
||||
// ? path.posix.basename(url.parse(req.query.code as string).pathname as string)
|
||||
// : req.query.code;
|
||||
|
||||
console.log(code);
|
||||
const game = activeGames.find((g) => g.code === code);
|
||||
// console.log(code);
|
||||
// const game = activeGames.find((g) => g.code === code);
|
||||
|
||||
if (!game) {
|
||||
res.status(404).end();
|
||||
} else {
|
||||
res.status(200).json(game);
|
||||
}*/
|
||||
// if (!game) {
|
||||
// res.status(404).end();
|
||||
// } else {
|
||||
// res.status(200).json(game);
|
||||
// }
|
||||
} catch (err: unknown) {
|
||||
console.log(err);
|
||||
res.status(500).end();
|
||||
@@ -40,9 +38,10 @@ export const createGame = async (req: Request, res: Response) => {
|
||||
return;
|
||||
}
|
||||
const user: User = req.session.user;
|
||||
const unlisted: boolean = req.body.unlisted ?? false;
|
||||
const game: Game = {
|
||||
code: nanoid(6),
|
||||
open: true,
|
||||
unlisted,
|
||||
host: user
|
||||
};
|
||||
if (req.body.side === "white") {
|
||||
|
||||
Reference in New Issue
Block a user