This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
62 lines (54 loc) · 1.5 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
56
57
58
59
60
61
62
import createFastify, { FastifyInstance, FastifyServerOptions } from "fastify";
import { searchRouter } from "./api/search";
import { checkRouter } from "./api/check";
const buildFastify = async (
options: FastifyServerOptions = {}
): Promise<FastifyInstance> => {
const fastifyRequestLogger = (await import("@mgcrea/fastify-request-logger"))
.default;
let fastify: FastifyInstance;
if (process.env.LOGTAIL_TOKEN) {
fastify = createFastify({
logger: {
level: "debug",
transport: {
target: "@logtail/pino",
options: {
sourceToken: process.env.LOGTAIL_TOKEN,
translateTime: "HH:MM:ss Z",
ignore: "pid,hostname,plugin",
},
},
},
...options,
});
} else {
fastify = createFastify({
logger: {
level: "debug",
transport: {
target: "pino-pretty",
options: {
translateTime: "HH:MM:ss Z",
ignore: "pid,hostname,plugin",
},
},
},
...options,
});
}
fastify.register(fastifyRequestLogger);
return fastify;
};
(async () => {
const app = await buildFastify();
app.register(searchRouter, { prefix: "/search" });
app.register(checkRouter, { prefix: "/check" });
app.get("/ping", (req, res) => {
res.send("pong");
});
app.listen({ port: parseInt(process.env.PORT || "3000") }).then(() => {
// @ts-ignore
console.log(`server listening on port ${app.server.address()?.port}`);
});
})();