blob: acd0475302e3ca41ee0e4a3552e8446bd3594445 (
plain) (
blame)
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 config from "$config";
import fastify from "fastify";
import fastifyWs from "@fastify/websocket";
import fastifyMultipart from "@fastify/multipart";
import fastifyStatic from "@fastify/static";
import fastifyPassport from "@fastify/passport";
import fastifySecureSession from "@fastify/secure-session";
import path from "path";
import pino from "pino";
import { jwtStrategy } from "$lib/auth";
import { socketServer } from "$lib/sockets";
const app = fastify({
logger: pino(),
disableRequestLogging: true,
maxParamLength: 500
});
app.register(fastifySecureSession, {
key: Buffer.from(config.jwt, "hex")
});
app.register(fastifyPassport.initialize());
app.register(fastifyPassport.secureSession());
fastifyPassport.use("jwt", jwtStrategy);
app.register(fastifyMultipart);
app.register(fastifyStatic, {
root: path.join("/app/data/uploads"),
prefix: "/public/"
});
app.register(fastifyWs);
app.register(socketServer);
app.setErrorHandler((error, request, reply) => {
if (error instanceof fastify.errorCodes.FST_ERR_BAD_STATUS_CODE) {
reply.status(500).send({ ok: false });
} else {
reply.send(error);
}
});
app.setNotFoundHandler((request, reply) => {
reply
.code(404)
.type("text/html")
.send("Not Found");
});
export default app;
|