diff options
| author | Adam Soltys <[email protected]> | 2024-08-26 23:22:02 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-26 23:22:02 -0700 |
| commit | 48f9e8b0de151edcf49903277d714d939f0b3d8f (patch) | |
| tree | dec717fb60ff14399872c8c7d36fffa4597e02cd /lib | |
| parent | 4efa82b36b74c633681ed831d6f567ae5ab08c3b (diff) | |
| download | coinos-server-48f9e8b0de151edcf49903277d714d939f0b3d8f.tar.gz coinos-server-48f9e8b0de151edcf49903277d714d939f0b3d8f.zip | |
more ts housekeeping
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/app.ts | 31 | ||||
| -rw-r--r-- | lib/sockets.ts | 8 |
2 files changed, 21 insertions, 18 deletions
@@ -4,9 +4,11 @@ import fastifyMultipart from "@fastify/multipart"; import fastifyStatic from "@fastify/static"; import fastifyPassport from "@fastify/passport"; import fastifySecureSession from "@fastify/secure-session"; +import fastifyProxy from "@fastify/http-proxy"; +import fastifyRateLimit from "@fastify/rate-limit"; import cors from "@fastify/cors"; -import path from "path"; +import * as path from "path"; import pino from "pino"; import { jwtStrategy } from "$lib/auth"; @@ -17,12 +19,12 @@ const app = fastify({ maxParamLength: 500, }); -await app.register(import("@fastify/rate-limit"), { - allowList: (req, key) => req.raw.url.includes("public"), +app.register(fastifyRateLimit, { + allowList: (req) => req.raw.url?.includes("public"), max: 100, timeWindow: 2000, - keyGenerator: (req) => req.headers["cf-connecting-ip"], - errorResponseBuilder: (req, context) => { + keyGenerator: (req) => req.headers["cf-connecting-ip"] as string, + errorResponseBuilder: () => { return { statusCode: 429, error: "Too Many Requests", @@ -31,6 +33,13 @@ await app.register(import("@fastify/rate-limit"), { }, }); +app.register(fastifyProxy, { + upstream: "http://localhost:3120", + prefix: "/ws", + rewritePrefix: "/ws", + websocket: true +}); + app.register(fastifySecureSession, { key: Buffer.from(config.jwt, "hex"), }); @@ -47,11 +56,9 @@ app.register(fastifyStatic, { prefix: "/public/", }); -await app.register(cors, { - origin: true, -}); +await app.register(cors, { origin: true }); -app.setErrorHandler((error, request, reply) => { +app.setErrorHandler((error, _, reply) => { if (error instanceof fastify.errorCodes.FST_ERR_BAD_STATUS_CODE) { reply.status(500).send({ ok: false }); } else { @@ -59,8 +66,8 @@ app.setErrorHandler((error, request, reply) => { } }); -app.setNotFoundHandler((request, reply) => { - reply.code(404).type("text/html").send("Not Found"); -}); +app.setNotFoundHandler((_, reply) => + reply.code(404).type("text/html").send("Not Found"), +); export default app; diff --git a/lib/sockets.ts b/lib/sockets.ts index 0391a07a..6ac75cb8 100644 --- a/lib/sockets.ts +++ b/lib/sockets.ts @@ -1,16 +1,12 @@ -import config from "$config"; import store from "$lib/store"; import jwt from "jsonwebtoken"; import { v4 } from "uuid"; -import whitelist from "$lib/whitelist"; -import { l, err, warn } from "$lib/logging"; -import { g } from "$lib/db"; -import { fail, getUser, pick } from "$lib/utils"; +import { err, warn } from "$lib/logging"; +import { fail, getUser } from "$lib/utils"; const code = 1000; const all = {}; const subscriptions = []; -const lastSeen = {}; const users = {}; export const emit = (uid, type, data) => { |
