Portage complet PHP/Bash vers Node.js (Fastify + worker_threads)

This commit is contained in:
unfr
2026-04-23 08:37:48 +02:00
parent 2f7c990376
commit 3563de52e9
28 changed files with 3348 additions and 0 deletions

60
server.js Normal file
View File

@@ -0,0 +1,60 @@
import Fastify from 'fastify';
import formbody from '@fastify/formbody';
import secureSession from '@fastify/secure-session';
import fastifyStatic from '@fastify/static';
import { join } from 'node:path';
import { ROOT, PORT, HOST, SESSION_SECRET } from './config.js';
import indexRoutes from './routes/index.js';
import apiRoutes from './routes/api.js';
import searchRoutes from './routes/search.js';
import { getRatings } from './lib/imdbRatings.js';
import { getPool } from './lib/searchEngine.js';
const fastify = Fastify({ logger: true, trustProxy: true });
await fastify.register(formbody);
await fastify.register(secureSession, {
// 32 bytes minimum. Use SESSION_SECRET env var in production.
secret: SESSION_SECRET.padEnd(32, '0').slice(0, 32),
salt: 'proxytmdb-salt-1',
cookieName: 'session',
cookie: {
path: '/',
httpOnly: true,
sameSite: 'lax',
secure: 'auto',
},
});
await fastify.register(indexRoutes);
await fastify.register(apiRoutes);
await fastify.register(searchRoutes);
// Serve any other path as a static file from the project root, so that the
// "directory listing" links keep working exactly as they did under Apache.
await fastify.register(fastifyStatic, {
root: ROOT,
serve: true,
index: false,
list: false,
decorateReply: false,
prefix: '/',
});
// Warm up: load IMDb ratings and spawn search workers eagerly.
fastify.ready().then(async () => {
try {
await getRatings();
getPool('movie');
getPool('tv');
fastify.log.info('Warmup complete');
} catch (err) {
fastify.log.warn({ err }, 'Warmup failed');
}
});
fastify.listen({ port: PORT, host: HOST }).catch((err) => {
fastify.log.error(err);
process.exit(1);
});