forked from
stevedylan.dev/sequoia
A CLI for publishing standard.site documents to ATProto
1import { Hono } from "hono";
2import { cors } from "hono/cors";
3import { RedisClient } from "bun";
4import { loadEnv } from "./env";
5import type { Env } from "./env";
6import auth from "./routes/auth";
7import subscribe from "./routes/subscribe";
8
9const env = loadEnv();
10
11const redis = new RedisClient(env.REDIS_URL);
12
13type Variables = { env: Env; redis: typeof redis };
14
15const app = new Hono<{ Variables: Variables }>();
16
17// Inject env and redis into all routes
18app.use("*", async (c, next) => {
19 c.set("env", env);
20 c.set("redis", redis);
21 await next();
22});
23
24// Health check
25app.get("/api/health", (c) => c.json({ status: "ok" }));
26
27// OAuth routes
28app.route("/oauth", auth);
29
30// Subscribe routes with CORS
31app.use(
32 "/subscribe/*",
33 cors({
34 origin: (origin) => origin,
35 credentials: true,
36 }),
37);
38app.use(
39 "/subscribe",
40 cors({
41 origin: (origin) => origin,
42 credentials: true,
43 }),
44);
45app.route("/subscribe", subscribe);
46
47console.log(`Sequoia server listening on port ${env.PORT}`);
48
49export default {
50 port: env.PORT,
51 fetch: app.fetch,
52};