Skip to content

Commit

Permalink
#fix: cors
Browse files Browse the repository at this point in the history
  • Loading branch information
akvlad committed Oct 31, 2023
1 parent 48a01d5 commit d3b0beb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion qryn_bun.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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()) })
Expand Down

0 comments on commit d3b0beb

Please sign in to comment.