mirror of
https://github.com/versia-pub/server.git
synced 2026-04-27 20:59:15 +02:00
refactor: 🚚 Organize code into sub-packages, instead of a single large package
This commit is contained in:
parent
79742f47dc
commit
a6d3ebbeef
366 changed files with 942 additions and 833 deletions
16
packages/api/middlewares/agent-bans.ts
Normal file
16
packages/api/middlewares/agent-bans.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { ApiError } from "@versia/kit";
|
||||
import { config } from "@versia-server/config";
|
||||
import { createMiddleware } from "hono/factory";
|
||||
|
||||
export const agentBans = createMiddleware(async (context, next) => {
|
||||
// Check for banned user agents (regex)
|
||||
const ua = context.req.header("user-agent") ?? "";
|
||||
|
||||
for (const agent of config.http.banned_user_agents) {
|
||||
if (new RegExp(agent).test(ua)) {
|
||||
throw new ApiError(403, "Forbidden");
|
||||
}
|
||||
}
|
||||
|
||||
await next();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue