Openstatus
www.openstatus.dev
1import { sentry } from "@hono/sentry";
2import { Hono } from "hono";
3import { showRoutes } from "hono/dev";
4import { logger } from "hono/logger";
5
6import { prettyJSON } from "hono/pretty-json";
7import { requestId } from "hono/request-id";
8import { env } from "./env";
9import { handleError } from "./libs/errors";
10import { publicRoute } from "./routes/public";
11import { api } from "./routes/v1";
12
13export const app = new Hono({ strict: false });
14
15/**
16 * Middleware
17 */
18app.use("*", sentry({ dsn: process.env.SENTRY_DSN }));
19app.use("*", requestId());
20app.use("*", logger());
21app.use("*", prettyJSON());
22
23app.onError(handleError);
24
25/**
26 * Public Routes
27 */
28app.route("/public", publicRoute);
29
30/**
31 * Ping Pong
32 */
33app.get("/ping", (c) => {
34 return c.json(
35 { ping: "pong", region: env.FLY_REGION, requestId: c.get("requestId") },
36 200,
37 );
38});
39
40/**
41 * API Routes v1
42 */
43app.route("/v1", api);
44
45/**
46 * TODO: move to `workflows` app
47 * This route is used by our checker to update the status of the monitors,
48 * create incidents, and send notifications.
49 */
50
51const isDev = process.env.NODE_ENV === "development";
52const port = 3000;
53
54if (isDev) showRoutes(app, { verbose: true, colorize: true });
55
56console.log(`Starting server on port ${port}`);
57
58const server = { port, fetch: app.fetch };
59
60export default server;