generated from nhcarrigan/template
All checks were successful
Node.js CI / Lint and Test (pull_request) Successful in 1m48s
45 lines
1.2 KiB
TypeScript
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.");
|
|
}
|
|
});
|