🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
fix allowlist
Bill Yang05292f9ebb84
diff --git a/server/src/index.ts b/server/src/index.tsindex 37a6ef9cc..312b04970 100644--- a/server/src/index.ts+++ b/server/src/index.ts@@ -38,17 +38,17 @@ const server = Fastify({trustProxy: true,});-// Register CORS-server.register(async (fastify) => {- const domains = await sql`SELECT domain FROM sites`;- fastify.register(cors, {- origin: [- "http://localhost:3002",- "https://tracking.tomato.gg",- ...domains.map(({ domain }) => `https://${domain}`),- ],- credentials: true,- });+const domains = await sql`SELECT domain FROM sites`;+const allowList = [+ "http://localhost:3002",+ "https://tracking.tomato.gg",+ ...domains.map(({ domain }) => `https://${domain}`),+];+initAuth(allowList);++server.register(cors, {+ origin: allowList,+ credentials: true,});// Serve static files@@ -57,8 +57,6 @@ server.register(fastifyStatic, {prefix: "/", // or whatever prefix you need});-await initAuth();-server.register(async (fastify, options) => {await fastify.register((fastify) => {diff --git a/server/src/lib/auth.ts b/server/src/lib/auth.tsindex 8bc8fd986..e707f02f2 100644--- a/server/src/lib/auth.ts+++ b/server/src/lib/auth.ts@@ -1,8 +1,7 @@import { betterAuth } from "better-auth";-import pg from "pg";import { username } from "better-auth/plugins";import dotenv from "dotenv";-import { sql } from "../db/postgres/postgres.js";+import pg from "pg";dotenv.config();@@ -10,9 +9,7 @@ type AuthType = ReturnType<typeof betterAuth> | null;export let auth: AuthType | null = null;-export const initAuth = async () => {- const domains = await sql`SELECT domain FROM sites`;- console.info(domains);+export const initAuth = (allowList: string[]) => {auth = betterAuth({basePath: "/auth",database: new pg.Pool({@@ -26,11 +23,6 @@ export const initAuth = async () => {enabled: true,},plugins: [username()],- trustedOrigins: [- "http://localhost:3002",- "http://localhost:3001",- "https://tracking.tomato.gg",- ...domains.map(({ domain }) => `https://${domain}`),- ],+ trustedOrigins: allowList,});};