mirror of
https://github.com/kennethnym/aris.git
synced 2026-05-07 09:01:19 +01:00
Compare commits
2 Commits
c95c730533
...
fix/backen
| Author | SHA1 | Date | |
|---|---|---|---|
|
464cbe4fa3
|
|||
|
09ad98990c
|
@@ -16,6 +16,9 @@ export function createAuth(db: Database) {
|
|||||||
provider: "pg",
|
provider: "pg",
|
||||||
schema,
|
schema,
|
||||||
}),
|
}),
|
||||||
|
advanced: {
|
||||||
|
disableCSRFCheck: process.env.NODE_ENV !== "production",
|
||||||
|
},
|
||||||
emailAndPassword: {
|
emailAndPassword: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Hono } from "hono"
|
import { Hono } from "hono"
|
||||||
|
import { cors } from "hono/cors"
|
||||||
|
|
||||||
import { registerAdminHttpHandlers } from "./admin/http.ts"
|
import { registerAdminHttpHandlers } from "./admin/http.ts"
|
||||||
import { createRequireAdmin } from "./auth/admin-middleware.ts"
|
import { createRequireAdmin } from "./auth/admin-middleware.ts"
|
||||||
@@ -50,6 +51,34 @@ function main() {
|
|||||||
|
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
|
|
||||||
|
const isDev = process.env.NODE_ENV !== "production"
|
||||||
|
const allowedOrigins = process.env.CORS_ORIGINS?.split(",").map((o) => o.trim()) ?? []
|
||||||
|
|
||||||
|
function resolveOrigin(origin: string): string | undefined {
|
||||||
|
if (isDev) return origin
|
||||||
|
return allowedOrigins.includes(origin) ? origin : undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
app.use(
|
||||||
|
"/api/auth/*",
|
||||||
|
cors({
|
||||||
|
origin: resolveOrigin,
|
||||||
|
allowHeaders: ["Content-Type", "Authorization"],
|
||||||
|
allowMethods: ["POST", "GET", "OPTIONS"],
|
||||||
|
exposeHeaders: ["Content-Length"],
|
||||||
|
maxAge: 600,
|
||||||
|
credentials: true,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
app.use(
|
||||||
|
"*",
|
||||||
|
cors({
|
||||||
|
origin: resolveOrigin,
|
||||||
|
credentials: true,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
app.get("/health", (c) => c.json({ status: "ok" }))
|
app.get("/health", (c) => c.json({ status: "ok" }))
|
||||||
|
|
||||||
const authSessionMiddleware = createRequireSession(auth)
|
const authSessionMiddleware = createRequireSession(auth)
|
||||||
|
|||||||
Reference in New Issue
Block a user