Files
hikari/server/src/index.ts
Naomi Carrigan 2103a02a84
All checks were successful
Node.js CI / Lint and Test (pull_request) Successful in 1m48s
chore: naomi fucked it up
2025-07-05 19:24:18 -07:00

45 lines
1.2 KiB
TypeScript

/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import cors from "@fastify/cors";
import fastify from "fastify";
import { corsHook } from "./hooks/cors.js";
import { ipHook } from "./hooks/ips.js";
import { announcementRoutes } from "./routes/announcement.js";
import { baseRoutes } from "./routes/base.js";
import { logger } from "./utils/logger.js";
const server = fastify({
logger: false,
});
/**
* This needs to be first, to ensure all requests have CORS configured.
* Our CORS settings allow for any origin, because we have a custom hook
* that guards specific routes from CORS requests.
* This is to allow our uptime monitor to access the health check route, for example.
* @see routesWithoutCors.ts
*/
server.register(cors, {
origin: "*",
});
server.addHook("preHandler", corsHook);
server.addHook("preHandler", ipHook);
server.register(baseRoutes);
server.register(announcementRoutes);
server.listen({ port: 20_000 }, (error) => {
if (error) {
void logger.error("instantiate server", error);
return;
}
if (process.env.NODE_ENV !== "dev") {
void logger.log("debug", "Server listening on port 20000.");
}
});