Skip to content

Open-source status page, incident response and uptime monitoring

🔥 hono v4 (#639)

Thibault Le Ouay4c164f2df817
diff --git a/apps/server/package.json b/apps/server/package.json
index 03903121b..d09aa82eb 100644
--- a/apps/server/package.json
+++ b/apps/server/package.json
@@ -25,7 +25,7 @@
"@openstatus/utils": "workspace:*",
"@t3-oss/env-core": "0.7.1",
"@unkey/api": "0.16.0",
- "hono": "3.9.2",
+ "hono": "4.0.0",
"nanoid": "5.0.2",
"zod": "3.22.2"
},
diff --git a/apps/server/src/index.ts b/apps/server/src/index.ts
index 29c3d5ae7..fdcefbd50 100644
--- a/apps/server/src/index.ts
+++ b/apps/server/src/index.ts
@@ -1,5 +1,6 @@
import { sentry } from "@hono/sentry";
import { Hono } from "hono";
+import { showRoutes } from "hono/dev";
import { logger } from "hono/logger";
import { checkerRoute } from "./checker";
@@ -31,7 +32,7 @@ app.route("/", checkerRoute);
const isDev = process.env.NODE_ENV === "development";
const port = isDev ? 3001 : 3000;
-if (isDev) app.showRoutes();
+if (isDev) showRoutes(app, { verbose: true, colorize: true });
console.log(`Starting server on port ${port}`);
diff --git a/apps/server/src/v1/incidents.ts b/apps/server/src/v1/incidents.ts
index 65e7a3df7..f7ea97632 100644
--- a/apps/server/src/v1/incidents.ts
+++ b/apps/server/src/v1/incidents.ts
@@ -102,10 +102,10 @@ incidentsApi.openapi(getAllRoute, async (c) => {
.where(eq(incidentTable.workspaceId, workspaceId))
.all();
- if (!result) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!result) return c.json({ code: 404, message: "Not Found" }, 404);
const data = z.array(IncidentSchema).parse(result);
- return c.jsonT(data);
+ return c.json(data);
});
const getRoute = createRoute({
@@ -152,10 +152,10 @@ incidentsApi.openapi(getRoute, async (c) => {
)
.get();
- if (!result) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!result) return c.json({ code: 404, message: "Not Found" }, 404);
const data = IncidentSchema.parse(result);
- return c.jsonT(data);
+ return c.json(data);
});
const incidentInputSchema = z
@@ -204,7 +204,7 @@ incidentsApi.openapi(putRoute, async (c) => {
const input = c.req.valid("json");
const workspaceId = Number(c.get("workspaceId"));
const { id } = c.req.valid("param");
- if (!id) return c.jsonT({ code: 400, message: "Bad Request" }, 400);
+ if (!id) return c.json({ code: 400, message: "Bad Request" }, 400);
const _incident = await db
.select()
@@ -217,10 +217,10 @@ incidentsApi.openapi(putRoute, async (c) => {
)
.get();
- if (!_incident) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!_incident) return c.json({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _incident.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
+ return c.json({ code: 401, message: "Unauthorized" }, 401);
const _newIncident = await db
.update(incidentTable)
@@ -233,7 +233,7 @@ incidentsApi.openapi(putRoute, async (c) => {
const data = IncidentSchema.parse(_newIncident);
- return c.jsonT(data);
+ return c.json(data);
});
export { incidentsApi };
diff --git a/apps/server/src/v1/monitor.ts b/apps/server/src/v1/monitor.ts
index 680d6d4aa..eda543713 100644
--- a/apps/server/src/v1/monitor.ts
+++ b/apps/server/src/v1/monitor.ts
@@ -208,11 +208,11 @@ monitorApi.openapi(getAllRoute, async (c) => {
.where(eq(monitor.workspaceId, workspaceId))
.all();
- if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!_monitor) return c.json({ code: 404, message: "Not Found" }, 404);
const data = z.array(MonitorSchema).parse(_monitor);
- return c.jsonT(data);
+ return c.json(data);
});
const getRoute = createRoute({
@@ -262,14 +262,14 @@ monitorApi.openapi(getRoute, async (c) => {
.where(eq(monitor.id, monitorId))
.get();
- if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!_monitor) return c.json({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _monitor.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
+ return c.json({ code: 401, message: "Unauthorized" }, 401);
const data = MonitorSchema.parse(_monitor);
- return c.jsonT(data);
+ return c.json(data);
});
const postRoute = createRoute({
@@ -329,9 +329,9 @@ monitorApi.openapi(postRoute, async (c) => {
)[0].count;
if (count >= workspacePlan.limits.monitors)
- return c.jsonT({ code: 403, message: "Forbidden" }, 403);
+ return c.json({ code: 403, message: "Forbidden" }, 403);
if (!workspacePlan.limits.periodicity.includes(input.periodicity))
- return c.jsonT({ code: 403, message: "Forbidden" }, 403);
+ return c.json({ code: 403, message: "Forbidden" }, 403);
const { headers, ...rest } = input;
const _newMonitor = await db
@@ -346,7 +346,7 @@ monitorApi.openapi(postRoute, async (c) => {
const data = MonitorSchema.parse(_newMonitor);
- return c.jsonT(data);
+ return c.json(data);
});
const putRoute = createRoute({
@@ -391,10 +391,10 @@ monitorApi.openapi(putRoute, async (c) => {
const workspacePlan = c.get("workspacePlan");
const { id } = c.req.valid("param");
- if (!id) return c.jsonT({ code: 400, message: "Bad Request" }, 400);
+ if (!id) return c.json({ code: 400, message: "Bad Request" }, 400);
if (!workspacePlan.limits.periodicity.includes(input.periodicity))
- return c.jsonT({ code: 403, message: "Forbidden" }, 403);
+ return c.json({ code: 403, message: "Forbidden" }, 403);
const _monitor = await db
.select()
@@ -402,10 +402,10 @@ monitorApi.openapi(putRoute, async (c) => {
.where(eq(monitor.id, Number(id)))
.get();
- if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!_monitor) return c.json({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _monitor.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
+ return c.json({ code: 401, message: "Unauthorized" }, 401);
const { headers, ...rest } = input;
const _newMonitor = await db
@@ -419,7 +419,7 @@ monitorApi.openapi(putRoute, async (c) => {
const data = MonitorSchema.parse(_newMonitor);
- return c.jsonT(data);
+ return c.json(data);
});
const deleteRoute = createRoute({
@@ -465,13 +465,13 @@ monitorApi.openapi(deleteRoute, async (c) => {
.where(eq(monitor.id, monitorId))
.get();
- if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!_monitor) return c.json({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _monitor.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
+ return c.json({ code: 401, message: "Unauthorized" }, 401);
await db.delete(monitor).where(eq(monitor.id, monitorId)).run();
- return c.jsonT({ message: "Deleted" });
+ return c.json({ message: "Deleted" });
});
const dailyStatsSchema = z.object({
@@ -538,17 +538,17 @@ monitorApi.openapi(getMonitorStats, async (c) => {
.where(eq(monitor.id, monitorId))
.get();
- if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!_monitor) return c.json({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _monitor.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
+ return c.json({ code: 401, message: "Unauthorized" }, 401);
const cache = await redis.get<z.infer<typeof dailyStatsSchemaArray>>(
`${monitorId}-daily-stats`,
);
if (cache) {
console.log("fetching from cache");
- return c.jsonT({
+ return c.json({
data: cache,
});
}
@@ -563,7 +563,7 @@ monitorApi.openapi(getMonitorStats, async (c) => {
await redis.set(`${monitorId}-daily-stats`, res.data, { ex: 600 });
- return c.jsonT({ data: res.data });
+ return c.json({ data: res.data });
});
export { monitorApi };
diff --git a/apps/server/src/v1/page.ts b/apps/server/src/v1/page.ts
index 799c19057..96f7d34e1 100644
--- a/apps/server/src/v1/page.ts
+++ b/apps/server/src/v1/page.ts
@@ -84,7 +84,7 @@ pageApi.openapi(postRouteSubscriber, async (c) => {
.where(and(eq(page.id, pageId), eq(page.workspaceId, workspaceId)))
.get();
- if (!_page) return c.jsonT({ code: 401, message: "Not authorized" }, 401);
+ if (!_page) return c.json({ code: 401, message: "Not authorized" }, 401);
const alreadySubscribed = await db
.select()
@@ -97,7 +97,7 @@ pageApi.openapi(postRouteSubscriber, async (c) => {
)
.get();
if (alreadySubscribed)
- return c.jsonT({ code: 401, message: "Already subscribed" }, 401);
+ return c.json({ code: 401, message: "Already subscribed" }, 401);
// TODO: send email for verification
const token = (Math.random() + 1).toString(36).substring(10);
@@ -125,7 +125,7 @@ pageApi.openapi(postRouteSubscriber, async (c) => {
const data = pageSubscriberSchema.parse(_statusReportSubscriberUpdate);
- return c.jsonT({
+ return c.json({
...data,
});
});
diff --git a/apps/server/src/v1/statusReport.ts b/apps/server/src/v1/statusReport.ts
index 22e1de026..89b9ac8b7 100644
--- a/apps/server/src/v1/statusReport.ts
+++ b/apps/server/src/v1/statusReport.ts
@@ -8,9 +8,8 @@ import {
statusReport,
statusReportStatus,
statusReportUpdate,
- workspacePlans,
} from "@openstatus/db/src/schema";
-import { sendEmail, sendEmailHtml } from "@openstatus/emails/emails/send";
+import { sendEmailHtml } from "@openstatus/emails/emails/send";
import { allPlans } from "@openstatus/plans";
import type { Variables } from "./index";
@@ -101,7 +100,7 @@ statusReportApi.openapi(getAllRoute, async (c) => {
where: eq(statusReport.workspaceId, workspaceId),
});
- if (!_statusReports) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!_statusReports) return c.json({ code: 404, message: "Not Found" }, 404);
const data = z.array(statusReportExtendedSchema).parse(
_statusReports.map((statusReport) => ({
@@ -114,7 +113,7 @@ statusReportApi.openapi(getAllRoute, async (c) => {
})),
);
- return c.jsonT(data);
+ return c.json(data);
});
const getRoute = createRoute({
@@ -160,7 +159,7 @@ statusReportApi.openapi(getRoute, async (c) => {
),
});
- if (!_statusUpdate) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!_statusUpdate) return c.json({ code: 404, message: "Not Found" }, 404);
const data = statusReportExtendedSchema.parse({
..._statusUpdate,
status_report_updates: _statusUpdate.statusReportUpdates.map(
@@ -168,7 +167,7 @@ statusReportApi.openapi(getRoute, async (c) => {
),
});
- return c.jsonT(data);
+ return c.json(data);
});
const postRoute = createRoute({
@@ -221,7 +220,7 @@ statusReportApi.openapi(postRoute, async (c) => {
const data = statusReportExtendedSchema.parse(_newStatusReport);
- return c.jsonT(data);
+ return c.json(data);
});
const deleteRoute = createRoute({
@@ -267,16 +266,16 @@ statusReportApi.openapi(deleteRoute, async (c) => {
.where(eq(statusReport.id, statusReportId))
.get();
- if (!_statusReport) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!_statusReport) return c.json({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _statusReport.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
+ return c.json({ code: 401, message: "Unauthorized" }, 401);
await db
.delete(statusReport)
.where(eq(statusReport.id, statusReportId))
.run();
- return c.jsonT({ message: "Deleted" });
+ return c.json({ message: "Deleted" });
});
const postRouteUpdate = createRoute({
@@ -332,7 +331,7 @@ statusReportApi.openapi(postRouteUpdate, async (c) => {
)
.get();
- if (!_statusReport) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!_statusReport) return c.json({ code: 404, message: "Not Found" }, 404);
const _statusReportUpdate = await db
.insert(statusReportUpdate)
@@ -382,7 +381,7 @@ statusReportApi.openapi(postRouteUpdate, async (c) => {
}
const data = statusUpdateSchema.parse(_statusReportUpdate);
- return c.jsonT({
+ return c.json({
...data,
});
});
diff --git a/apps/server/src/v1/statusReportUpdate.ts b/apps/server/src/v1/statusReportUpdate.ts
index d218030b8..86917cbb2 100644
--- a/apps/server/src/v1/statusReportUpdate.ts
+++ b/apps/server/src/v1/statusReportUpdate.ts
@@ -96,7 +96,7 @@ statusReportUpdateApi.openapi(getUpdateRoute, async (c) => {
.where(eq(statusReportUpdate.id, Number(id)))
.get();
- if (!update) return c.jsonT({ code: 404, message: "Not Found" }, 404);
+ if (!update) return c.json({ code: 404, message: "Not Found" }, 404);
const currentStatusReport = await db
.select()
@@ -109,11 +109,11 @@ statusReportUpdateApi.openapi(getUpdateRoute, async (c) => {
)
.get();
if (!currentStatusReport)
- return c.jsonT({ code: 401, message: "Not Authorized" }, 401);
+ return c.json({ code: 401, message: "Not Authorized" }, 401);
const data = statusUpdateSchema.parse(update);
- return c.jsonT(data);
+ return c.json(data);
});
const createStatusUpdate = createRoute({
@@ -165,7 +165,7 @@ statusReportUpdateApi.openapi(createStatusUpdate, async (c) => {
)
.get();
if (!_currentStatusReport)
- return c.jsonT({ code: 401, message: "Not Authorized" }, 401);
+ return c.json({ code: 401, message: "Not Authorized" }, 401);
const res = await db
.insert(statusReportUpdate)
@@ -215,7 +215,7 @@ statusReportUpdateApi.openapi(createStatusUpdate, async (c) => {
}
}
const data = statusUpdateSchema.parse(res);
- return c.jsonT(data);
+ return c.json(data);
});
export { statusReportUpdateApi };
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c0d9045a5..84063a540 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -39,10 +39,10 @@ importers:
dependencies:
'@hono/sentry':
specifier: 1.0.0
- version: 1.0.0([email protected])
+ version: 1.0.0([email protected])
'@hono/zod-openapi':
specifier: 0.8.3
'@openstatus/db':
specifier: workspace:*
version: link:../../packages/db
@@ -80,8 +80,8 @@ importers:
specifier: 0.16.0
version: 0.16.0
hono:
- specifier: 3.9.2
- version: 3.9.2
+ specifier: 4.0.0
+ version: 4.0.0
nanoid:
specifier: 5.0.2
version: 5.0.2
@@ -2220,16 +2220,16 @@ packages:
tailwindcss: 3.3.2
dev: false
resolution: {integrity: sha512-GbPxgpGuasM2zRCSaA77MPWu4KDcuk/EMf7JJykjCvnOTbjmtr7FovNxsvg7xlXCIjZDgLmqBaoJMi3AxbeIAA==}
peerDependencies:
hono: 3.*
dependencies:
- hono: 3.9.2
+ hono: 4.0.0
toucan-js: 3.3.0
dev: false
resolution: {integrity: sha512-TwjSf63miIF3VBqNy4V6EOqZYdTQPeIQQ9Q2HjRWFYH9f2QtBFXziuqIg2Y76gNZ3WDal67NQXmbSErHiFR44g==}
engines: {node: '>=16.0.0'}
peerDependencies:
@@ -2237,18 +2237,18 @@ packages:
zod: 3.*
dependencies:
'@asteasolutions/zod-to-openapi': 5.5.0([email protected])
- '@hono/zod-validator': 0.1.9([email protected])([email protected])
- hono: 3.9.2
+ '@hono/zod-validator': 0.1.9([email protected])([email protected])
+ hono: 4.0.0
zod: 3.22.2
dev: false
resolution: {integrity: sha512-qEG5xagKzyif283ldCKzp+aF9Aebclg0sfrgyRQQNAizmXpicZ3UGduST/Jp+a9bjt3mI+VyEXMftb4rogLxQA==}
peerDependencies:
hono: 3.*
zod: ^3.19.1
dependencies:
- hono: 3.9.2
+ hono: 4.0.0
zod: 3.22.2
dev: false
@@ -8400,8 +8400,8 @@ packages:
react-is: 16.13.1
dev: false
- resolution: {integrity: sha512-180NOiMadqU3lGmN6ajPDZvZPWus3a9mtVaAUR9uG0SImngBwRLA8vbnV0oUfUAgFT4nX55sGV9dVA06OuikHA==}
+ resolution: {integrity: sha512-8dKhuBBpRZEodUttQhrSFJ6PQqHRjXHyeeegfxOf132pvgbf0tOb9qqb7q7eYwAWpOcYrsUOsWdJ0sQIIovhZg==}
engines: {node: '>=16.0.0'}
dev: false