-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
51 lines (42 loc) · 1.43 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Hono } from "hono";
import { cors } from "hono/cors";
import githubRouter from "./routes/githubRouter";
import { discordRouter } from "./routes/discordRouter";
import "./integrations/discord/listener.js";
import { apiLogger, Logger } from "./util/logger.js";
const app = new Hono({ strict: false });
app.use(apiLogger);
const allowedOrigins: string[] = [];
if (process.env.NODE_ENV === "production") {
if (!process.env.ALLOWED_PROD_ORIGIN) {
throw new Error("ALLOWED_PROD_ORIGIN not set in production environment");
}
allowedOrigins.push(process.env.ALLOWED_PROD_ORIGIN);
allowedOrigins.push("https://api.github.com");
allowedOrigins.push("https://www.github.com");
} else {
if (!process.env.ALLOWED_DEV_ORIGIN) {
throw new Error("ALLOWED_DEV_ORIGIN not set in development environment");
}
allowedOrigins.push(process.env.ALLOWED_DEV_ORIGIN);
allowedOrigins.push("http://localhost:8000");
allowedOrigins.push("http://localhost:3000");
allowedOrigins.push("http://127.0.0.1:8000");
}
app.use(
"/colony/*",
cors({
origin: allowedOrigins,
exposeHeaders: ["*"],
allowHeaders: ["Content-Type", "Authorization"],
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
})
);
app
.route("/colony/github", githubRouter)
.route("/colony/discord", discordRouter);
app.get("/", (c) => {
return c.text("Colony Engine API active");
});
Logger.log("info", "API is running");
export default app;