From 4b51fb8325acafac4e9231754dc58663f6431e1e Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 17 Jan 2023 12:33:17 -0800 Subject: rename app --- app.js | 40 ---------------------------------------- index.js | 2 +- lib/app.js | 40 ++++++++++++++++++++++++++++++++++++++++ lib/nostr.js | 1 - lib/sockets.js | 2 -- routes/events.js | 6 ------ routes/users.js | 1 - 7 files changed, 41 insertions(+), 51 deletions(-) delete mode 100644 app.js create mode 100644 lib/app.js delete mode 100644 routes/events.js diff --git a/app.js b/app.js deleted file mode 100644 index af2bd59f..00000000 --- a/app.js +++ /dev/null @@ -1,40 +0,0 @@ -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/uploads"), - prefix: "/public/" -}); - -app.register(fastifyWs); -app.register(socketServer); - -export default app; diff --git a/index.js b/index.js index 9d291355..ca33b646 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -import app from "$app"; +import app from "$lib/app"; import { auth, optional } from "$lib/auth"; import { fillPool } from "$lib/nostr"; diff --git a/lib/app.js b/lib/app.js new file mode 100644 index 00000000..af2bd59f --- /dev/null +++ b/lib/app.js @@ -0,0 +1,40 @@ +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/uploads"), + prefix: "/public/" +}); + +app.register(fastifyWs); +app.register(socketServer); + +export default app; diff --git a/lib/nostr.js b/lib/nostr.js index d4dc2e67..23ea937b 100644 --- a/lib/nostr.js +++ b/lib/nostr.js @@ -1,4 +1,3 @@ -import app from "$app"; import config from "$config"; import { Relay, RelayPool } from "nostr"; import { broadcast } from "$lib/sockets"; diff --git a/lib/sockets.js b/lib/sockets.js index 1105f94d..234c647a 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -1,4 +1,3 @@ -import app from "$app"; import config from "$config"; import store from "$lib/store"; import jwt from "jsonwebtoken"; @@ -83,7 +82,6 @@ export async function socketServer(app) { let { id: uid } = jwt.decode(token); if (!uid) throw new Error("Invalid JWT token"); let user = await g(`user:${uid}`); - console.log("uid", uid); if (!user) throw new Error("User not found"); if (!store.sockets[uid]) store.sockets[uid] = {}; diff --git a/routes/events.js b/routes/events.js deleted file mode 100644 index 21ee37d8..00000000 --- a/routes/events.js +++ /dev/null @@ -1,6 +0,0 @@ -import app from "$app"; -import db from "$db"; -import redis from "$lib/db"; -import { coinos, pool, q } from "$lib/nostr"; -import store from "$lib/store"; -import { nada, wait } from "$lib/utils"; diff --git a/routes/users.js b/routes/users.js index 0358e548..49aeebd7 100644 --- a/routes/users.js +++ b/routes/users.js @@ -1,4 +1,3 @@ -import app from "$app"; import { g, s } from "$lib/db"; import config from "$config"; import store from "$lib/store"; -- cgit v1.2.3