-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
55 lines (50 loc) · 1.67 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import "dotenv/config";
import path from "node:path";
import fastifyCookie from "@fastify/cookie";
import type { FastifyCookieOptions } from "@fastify/cookie";
import formbody from "@fastify/formbody";
import helmet from "@fastify/helmet";
import type { TypeBoxTypeProvider } from "@fastify/type-provider-typebox";
import pointOfView from "@fastify/view";
import ejs from "ejs";
import Fastify, { type FastifyInstance } from "fastify";
import apiRoutes from "./routes/api.js";
import frontendRoutes from "./routes/frontend.js";
const fastify: FastifyInstance = Fastify({
logger: true,
}).withTypeProvider<TypeBoxTypeProvider>();
fastify.register(helmet, {
contentSecurityPolicy: {
directives: {
// Not needed because all our requests will already be https in production.
// Also breaks Safari when accessing localhost.
upgradeInsecureRequests: null,
},
},
// For some reason setting this option to true makes Playwright tests occasionally timeout
// on page.goto commands.
crossOriginOpenerPolicy: false,
});
/**
* @todo store an actual session secret in env
* @todo use secure: true in prod env
*/
fastify.register(fastifyCookie, {
secret: "my-secret", // for cookies signature
parseOptions: {}, // options for parsing cookies
} as FastifyCookieOptions);
fastify.register(formbody);
fastify.register(pointOfView, {
engine: { ejs },
templates: path.join(import.meta.dirname, "frontend/templates"),
layout: "layout.ejs",
});
fastify.register(frontendRoutes);
fastify.register(apiRoutes, { prefix: "/api/v1" });
fastify.listen({ port: 3000 }, (err, address) => {
if (err) {
fastify.log.error(err);
process.exit(1);
}
console.log(`Server listening on ${address}`);
});