This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

more cors yay

+20 -6
+3 -3
src/control/server.ts
··· 4 4 import { existsSync } from "node:fs" 5 5 import { dirname, join } from "node:path" 6 6 import { fileURLToPath } from "node:url" 7 + import { CORS_HEADERS, applyCorsHeaders } from "../cors" 7 8 import { 8 9 getAgent, 9 10 listAgents, ··· 168 169 "cache-control": "no-cache", 169 170 connection: "keep-alive", 170 171 "x-accel-buffering": "no", 172 + ...CORS_HEADERS, 171 173 }) 172 174 downstream.write(":ok\n\n") 173 175 ··· 421 423 const app = Fastify({ logger: false }) 422 424 423 425 app.addHook("onRequest", async (_req, reply) => { 424 - reply.header("access-control-allow-origin", "*") 425 - reply.header("access-control-allow-methods", "GET,POST,OPTIONS") 426 - reply.header("access-control-allow-headers", "content-type,authorization") 426 + applyCorsHeaders(reply) 427 427 }) 428 428 429 429 app.options("/*", async (_req, reply) => reply.code(204).send())
+13
src/cors.ts
··· 1 + import type { FastifyReply } from "fastify" 2 + 3 + export const CORS_HEADERS = { 4 + "access-control-allow-origin": "*", 5 + "access-control-allow-methods": "GET,POST,OPTIONS", 6 + "access-control-allow-headers": "content-type,authorization", 7 + } as const 8 + 9 + export function applyCorsHeaders(reply: FastifyReply): void { 10 + for (const [name, value] of Object.entries(CORS_HEADERS)) { 11 + reply.header(name, value) 12 + } 13 + }
+4 -3
src/server.ts
··· 16 16 import { subscribe } from "./stream" 17 17 import { getMetrics, getMetricDetail, getDiscordMetricDetail } from "./metrics" 18 18 import { registerControlRoutes } from "./control/server" 19 + import { CORS_HEADERS, applyCorsHeaders } from "./cors" 19 20 import type { MetricListType } from "./metrics" 20 21 import type { UserMessage } from "./types" 21 22 ··· 63 64 let discordBatchTimer: ReturnType<typeof setInterval> | null = null 64 65 65 66 app.addHook("onRequest", async (_req, reply) => { 66 - reply.header("access-control-allow-origin", "*") 67 - reply.header("access-control-allow-methods", "GET,POST,OPTIONS") 68 - reply.header("access-control-allow-headers", "content-type,authorization") 67 + applyCorsHeaders(reply) 69 68 }) 70 69 71 70 app.options("/*", async (_req, reply) => reply.code(204).send()) ··· 207 206 "cache-control": "no-cache", 208 207 connection: "keep-alive", 209 208 "x-accel-buffering": "no", 209 + ...CORS_HEADERS, 210 210 }) 211 211 212 212 res.write(":ok\n\n") ··· 333 333 "cache-control": "no-cache", 334 334 connection: "keep-alive", 335 335 "x-accel-buffering": "no", 336 + ...CORS_HEADERS, 336 337 }) 337 338 338 339 // Send initial keepalive so the connection is established