From d3b0bebe406865951133b82e8b7a8f22feddd6c3 Mon Sep 17 00:00:00 2001 From: akvlad Date: Tue, 31 Oct 2023 18:03:23 +0200 Subject: [PATCH] #fix: cors --- qryn_bun.mjs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/qryn_bun.mjs b/qryn_bun.mjs index 33e7c57c..806f2ab7 100644 --- a/qryn_bun.mjs +++ b/qryn_bun.mjs @@ -53,7 +53,7 @@ import DATABASE, { init } from './lib/db/clickhouse.js' import { startAlerting } from './lib/db/alerting/index.js' import fs from 'fs' import path from 'path' -import { file, dir, group } from '@stricjs/utils'; +import { file, dir, group, CORS } from '@stricjs/utils'; import auth from 'basic-auth' import * as errors from 'http-errors' @@ -69,6 +69,16 @@ export default async() => { const app = new Router() + const cors = process.env.CORS_ALLOW_ORIGIN || '*' + + app.wrap('/', (resp) => { + const _cors = new CORS({allowOrigins: cors}) + for(const c of Object.entries(_cors.headers)) { + resp.headers.append(c[0], c[1]) + } + return resp + }) + app.guard("/", (ctx) => { if (http_user) { const creds = auth({ headers: Object.fromEntries(ctx.headers.entries()) })