(backend): trying to have a working backend.

Did I manage to achieve this task: NO.
This commit is contained in:
apetitco 2025-12-21 02:58:15 +01:00
parent b873ec390f
commit 8debc57559
14 changed files with 327 additions and 241 deletions

View file

@ -0,0 +1,7 @@
#!/bin/sh
set -e
# do anything here
# run the CMD [ ... ] from the dockerfile
exec "$@"

View file

@ -6,9 +6,8 @@
"scripts": {
"start": "npm run build && node dist/run.js",
"build": "vite build",
"build:prod": "vite build --outDir=/dist --minify=true --sourcemap=false",
"REMOVEME-build:openapi": "VITE_ENTRYPOINT=src/openapi.ts vite build && node dist/openapi.cjs >openapi.json",
"test": "echo \"Error: no test specified\" && exit 1"
"build:prod": "vite build --outDir=/dist --minify=true --sourcemap=false && mv /dist/run.js /dist/run.cjs",
"build:openapi": "VITE_ENTRYPOINT=src/openapi.ts vite build && mv dist/openapi.js dist/openapi.cjs && node dist/openapi.cjs >openapi.json"
},
"keywords": [],
"author": "",
@ -24,7 +23,7 @@
"fastify": "^5.6.2",
"fastify-plugin": "^5.1.0",
"socket.io": "^4.8.1",
"typebox": "^1.0.64"
"typebox": "^1.0.65"
},
"devDependencies": {
"@types/node": "^22.19.3",

View file

@ -0,0 +1,21 @@
import f, { FastifyPluginAsync } from 'fastify';
import * as swagger from '@shared/swagger';
import * as auth from '@shared/auth';
declare const __SERVICE_NAME: string;
// @ts-expect-error: import.meta.glob is a vite thing. Typescript doesn't know this...
const routes = import.meta.glob('./routes/**/*.ts', { eager: true });
async function start() {
const fastify = f({ logger: false });
await fastify.register(auth.authPlugin, { onlySchema: true });
await fastify.register(swagger.useSwagger, { service: __SERVICE_NAME });
for (const route of Object.values(routes)) {
await fastify.register(route as FastifyPluginAsync, {});
}
await fastify.ready();
console.log(JSON.stringify(fastify.swagger(), undefined, 4));
}
start();

View file

@ -6,13 +6,13 @@ import app from './app';
const start = async () => {
const envToLogger = {
development: {
transport: {
target: 'pino',
options: {
translateTime: 'HH:MM:ss Z',
ignore: 'pid,hostname',
},
},
// transport: {
// target: 'pino',
// options: {
// translateTime: 'HH:MM:ss Z',
// ignore: 'pid,hostname',
// },
// },
},
production: true,
test: false,

View file

@ -0,0 +1,54 @@
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
import nodeExternals from 'rollup-plugin-node-externals';
import path from 'node:path';
import fs from 'node:fs';
function collectDeps(...pkgJsonPaths) {
const allDeps = new Set();
for (const pkgPath of pkgJsonPaths) {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
for (const dep of Object.keys(pkg.dependencies || {})) {
allDeps.add(dep);
}
for (const peer of Object.keys(pkg.peerDependencies || {})) {
allDeps.add(peer);
}
}
return Array.from(allDeps);
}
const externals = collectDeps(
'./package.json',
'../@shared/package.json',
);
export default defineConfig({
root: __dirname,
define: {
__SERVICE_NAME: '"tic-tac-toe"',
},
// service root
plugins: [tsconfigPaths(), nodeExternals()],
build: {
ssr: true,
outDir: 'dist',
emptyOutDir: true,
lib: {
entry: path.resolve(__dirname, process.env.VITE_ENTRYPOINT ?? 'src/run.ts'),
// adjust main entry
formats: ['cjs'],
// CommonJS for Node.js
fileName: (format, entryName) => `${entryName}.cjs`,
},
rollupOptions: {
external: externals,
},
target: 'node22',
// or whatever Node version you use
sourcemap: true,
minify: false,
// for easier debugging
},
});