Add the Sokko TCG collectible card mini-game
Add the server-backed card game: Discord login, recharging pack openings, album, trades, gifts, stardust shop, campaign codes and its administration, stored in SQLite and disabled in production until configured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
243465720f
commit
5ce35cd7ba
193 changed files with 12159 additions and 28 deletions
13
server.mjs
13
server.mjs
|
|
@ -1,6 +1,7 @@
|
|||
// Rôle : sert l'application Vite construite ou les sources publiques avec leur politique de cache.
|
||||
import { createReadStream, existsSync, statSync } from "node:fs";
|
||||
import { loadProjectEnv } from "./scripts/load-project-env.mjs";
|
||||
import { createCardsApiHandler } from "./services/cards/api.js";
|
||||
import { createServer } from "node:http";
|
||||
import { extname, join, relative, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
|
@ -65,8 +66,9 @@ function getCacheControl(root, file) {
|
|||
return "no-cache";
|
||||
}
|
||||
|
||||
export function createStaticServer({ root = defaultRoot, publicRoot = defaultPublicRoot } = {}) {
|
||||
return createServer((req, res) => {
|
||||
export function createStaticServer({ root = defaultRoot, publicRoot = defaultPublicRoot, cardsApi = null } = {}) {
|
||||
const server = createServer(async (req, res) => {
|
||||
if (cardsApi && await cardsApi(req, res)) return;
|
||||
const file = resolvePath(req.url || "/", root, publicRoot);
|
||||
if (!file || !existsSync(file)) {
|
||||
res.writeHead(404, {
|
||||
|
|
@ -83,12 +85,15 @@ export function createStaticServer({ root = defaultRoot, publicRoot = defaultPub
|
|||
});
|
||||
createReadStream(file).pipe(res);
|
||||
});
|
||||
if (cardsApi?.close) server.once("close", cardsApi.close);
|
||||
return server;
|
||||
}
|
||||
|
||||
export function startServer() {
|
||||
export function startServer({ cardsApiOptions = {} } = {}) {
|
||||
loadProjectEnv();
|
||||
const port = Number(process.env.PORT || 5173);
|
||||
const server = createStaticServer();
|
||||
const cardsApi = createCardsApiHandler({ projectRoot, ...cardsApiOptions });
|
||||
const server = createStaticServer({ cardsApi });
|
||||
|
||||
server.on("error", (error) => {
|
||||
if (error.code === "EADDRINUSE") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue