diff options
| author | Adam Soltys <[email protected]> | 2024-08-26 21:17:43 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-26 21:17:43 -0700 |
| commit | fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7 (patch) | |
| tree | aa8f34e1692bd2d638a2c996eeadb58671d07aea /lib/app.js | |
| parent | 00e43ddc0bf3d6dd719fc9295d156567fa2fecfb (diff) | |
| download | coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.tar.gz coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.zip | |
typescript
Diffstat (limited to 'lib/app.js')
| -rw-r--r-- | lib/app.js | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/lib/app.js b/lib/app.js deleted file mode 100644 index 03ed3bb0..00000000 --- a/lib/app.js +++ /dev/null @@ -1,66 +0,0 @@ -import config from "$config"; -import fastify from "fastify"; -import fastifyMultipart from "@fastify/multipart"; -import fastifyStatic from "@fastify/static"; -import fastifyPassport from "@fastify/passport"; -import fastifySecureSession from "@fastify/secure-session"; -import cors from "@fastify/cors"; - -import path from "path"; -import pino from "pino"; - -import { jwtStrategy } from "$lib/auth"; - -const app = fastify({ - logger: pino(), - disableRequestLogging: true, - maxParamLength: 500, -}); - -await app.register(import("@fastify/rate-limit"), { - allowList: (req, key) => req.raw.url.includes("public"), - max: 100, - timeWindow: 2000, - keyGenerator: (req) => req.headers["cf-connecting-ip"], - errorResponseBuilder: (req, context) => { - return { - statusCode: 429, - error: "Too Many Requests", - message: "Rate limit exceeded, retry in 2 seconds", - }; - }, -}); - -app.register(fastifySecureSession, { - key: Buffer.from(config.jwt, "hex"), -}); - -app.register(fastifyPassport.initialize()); -app.register(fastifyPassport.secureSession()); - -fastifyPassport.use("jwt", jwtStrategy); - -app.register(fastifyMultipart, { limits: { fileSize: 10 ** 7 } }); - -app.register(fastifyStatic, { - root: path.join("/home/bun/app/data/uploads"), - prefix: "/public/", -}); - -await app.register(cors, { - origin: true, -}); - -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; |
