2024-05-29 02:59:49 +02:00
|
|
|
import { errorResponse } from "@/response";
|
2024-05-17 21:38:38 +02:00
|
|
|
import { createMiddleware } from "hono/factory";
|
2024-05-29 02:59:49 +02:00
|
|
|
import { config } from "~/packages/config-manager";
|
2024-05-17 21:38:38 +02:00
|
|
|
|
|
|
|
|
export const urlCheck = createMiddleware(async (context, next) => {
|
|
|
|
|
// Check that request URL matches base_url
|
|
|
|
|
const baseUrl = new URL(config.http.base_url);
|
|
|
|
|
|
|
|
|
|
if (new URL(context.req.url).origin !== baseUrl.origin) {
|
|
|
|
|
return errorResponse(
|
|
|
|
|
`Request URL ${context.req.url} does not match base URL ${baseUrl.origin}`,
|
|
|
|
|
400,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await next();
|
|
|
|
|
});
|