aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbun.lockbbin204761 -> 206855 bytes
-rw-r--r--lib/app.ts31
-rw-r--r--lib/sockets.ts8
-rw-r--r--package.json1
-rw-r--r--tsconfig.json8
5 files changed, 22 insertions, 26 deletions
diff --git a/bun.lockb b/bun.lockb
index 6aaed16c..d09fd8a7 100755
--- a/bun.lockb
+++ b/bun.lockb
Binary files differ
diff --git a/lib/app.ts b/lib/app.ts
index 03ed3bb0..fc86a3f2 100644
--- a/lib/app.ts
+++ b/lib/app.ts
@@ -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) => {
diff --git a/package.json b/package.json
index a4e70719..bd54dc30 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"@aws-sdk/client-ses": "^3.449.0",
"@cashu/cashu-ts": "^1.0.1",
"@fastify/cors": "^8.3.0",
+ "@fastify/http-proxy": "^9.5.0",
"@fastify/multipart": "^8.0.0",
"@fastify/passport": "^2.4.0",
"@fastify/rate-limit": "^9.1.0",
diff --git a/tsconfig.json b/tsconfig.json
index 0bee304a..60a23477 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -19,14 +19,6 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
- "noImplicitAny": false, // Allow variables to have 'any' type
- "noImplicitThis": false, // Allow 'this' to be of any type
- "strictNullChecks": false, // Disable strict null checks
- "strictFunctionTypes": false, // Disable strict function types
- "strictBindCallApply": false, // Disable strict bind/call/apply checks
- "noImplicitReturns": false, // Disable implicit return type checks
- "noFallthroughCasesInSwitch": false,
-
"baseUrl": ".",
"paths": {
"$lib/*": ["./lib/*.ts"],