2025-06-15 04:38:20 +02:00
|
|
|
import { config } from "@versia-server/config";
|
2024-12-18 20:42:40 +01:00
|
|
|
import { createMiddleware } from "hono/factory";
|
2024-05-17 21:38:38 +02:00
|
|
|
|
|
|
|
|
export const urlCheck = createMiddleware(async (context, next) => {
|
|
|
|
|
// Check that request URL matches base_url
|
2025-02-13 01:31:15 +01:00
|
|
|
const baseUrl = config.http.base_url;
|
2024-05-17 21:38:38 +02:00
|
|
|
|
|
|
|
|
if (new URL(context.req.url).origin !== baseUrl.origin) {
|
2024-08-19 21:03:59 +02:00
|
|
|
return context.json(
|
|
|
|
|
{
|
|
|
|
|
error: `Request URL ${context.req.url} does not match base URL ${baseUrl.origin}`,
|
|
|
|
|
},
|
2024-05-17 21:38:38 +02:00
|
|
|
400,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await next();
|
2025-05-23 17:29:27 +02:00
|
|
|
return;
|
2024-05-17 21:38:38 +02:00
|
|
|
});
|