| 1 | import { Hono } from "hono"; |
| 2 | import { cors } from "hono/cors"; |
| 3 | import auth from "./routes/auth"; |
| 4 | import subscribe from "./routes/subscribe"; |
| 5 | import recommend from "./routes/recommend"; |
| 6 | import "./lib/path-redirect"; |
| 7 | |
| 8 | type Bindings = { |
| 9 | ASSETS: Fetcher; |
| 10 | SEQUOIA_SESSIONS: KVNamespace; |
| 11 | CLIENT_URL: string; |
| 12 | }; |
| 13 | |
| 14 | const app = new Hono<{ Bindings: Bindings }>(); |
| 15 | |
| 16 | app.use( |
| 17 | "/subscribe", |
| 18 | cors({ |
| 19 | origin: (origin) => origin, |
| 20 | credentials: true, |
| 21 | }), |
| 22 | ); |
| 23 | app.use( |
| 24 | "/subscribe/*", |
| 25 | cors({ |
| 26 | origin: (origin) => origin, |
| 27 | credentials: true, |
| 28 | }), |
| 29 | ); |
| 30 | |
| 31 | app.route("/oauth", auth); |
| 32 | app.route("/subscribe", subscribe); |
| 33 | |
| 34 | app.use( |
| 35 | "/recommend", |
| 36 | cors({ |
| 37 | origin: (origin) => origin, |
| 38 | credentials: true, |
| 39 | }), |
| 40 | ); |
| 41 | app.use( |
| 42 | "/recommend/*", |
| 43 | cors({ |
| 44 | origin: (origin) => origin, |
| 45 | credentials: true, |
| 46 | }), |
| 47 | ); |
| 48 | app.route("/recommend", recommend); |
| 49 | |
| 50 | app.get("/api/health", (c) => { |
| 51 | return c.json({ status: "ok" }); |
| 52 | }); |
| 53 | |
| 54 | app.all("*", (c) => { |
| 55 | return c.env.ASSETS.fetch(c.req.raw); |
| 56 | }); |
| 57 | |
| 58 | export default app; |