|
1 | 1 | import { Hono } from "hono"; |
2 | 2 | import { logger } from "hono/logger"; |
| 3 | +import { cors } from "hono/cors"; |
3 | 4 | import { lokiLogger } from "./monitor/logger"; |
4 | 5 | import { prometheus } from "@hono/prometheus"; |
5 | 6 | import { otel } from "@hono/otel"; |
@@ -35,6 +36,33 @@ const PORT = process.env.PORT || 3000; |
35 | 36 |
|
36 | 37 | app.use(logger(lokiLogger)); |
37 | 38 |
|
| 39 | +// CORS configuration - allow all origins |
| 40 | +app.use( |
| 41 | + "*", |
| 42 | + cors({ |
| 43 | + origin: "*", // Allow all origins |
| 44 | + allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], |
| 45 | + allowHeaders: [ |
| 46 | + "Content-Type", |
| 47 | + "Authorization", |
| 48 | + "X-Requested-With", |
| 49 | + "Origin", |
| 50 | + "Accept", |
| 51 | + ], |
| 52 | + credentials: false, |
| 53 | + }) |
| 54 | +); |
| 55 | + |
| 56 | +// Additional explicit OPTIONS handler for preflight requests |
| 57 | +app.options("*", (c) => { |
| 58 | + return c.text("", 200, { |
| 59 | + "Access-Control-Allow-Origin": "*", |
| 60 | + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", |
| 61 | + "Access-Control-Allow-Headers": |
| 62 | + "Content-Type, Authorization, X-Requested-With, Origin, Accept", |
| 63 | + }); |
| 64 | +}); |
| 65 | + |
38 | 66 | app.use("*", registerMetrics, otel()); |
39 | 67 | app.get("/metrics", printMetrics); |
40 | 68 |
|
|
0 commit comments