-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
34 lines (26 loc) · 791 Bytes
/
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
import Fastify from "fastify";
import fastifyNextJs from "@fastify/nextjs";
import { parse } from "url";
import authRoutes from "./server/module/auth/auth.route";
import isDev from "./server/utils/isDev";
const server = Fastify({
pluginTimeout: isDev ? 100000 : 10000,
});
server.register(fastifyNextJs, { dev: isDev });
server.all("*", async (request, reply) => {
const parsedUrl = parse(request.url, true);
const { pathname } = parsedUrl as { pathname: string };
try {
await reply.nextRender(pathname);
} catch (err) {
console.log(err);
}
});
server.register(authRoutes, { prefix: "api/auth" });
server.listen({ port: 3000 }, (err, address) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log(`Server listening at ${address}`);
});