mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): ♻️ Remove old redirect() and response() in favour of Hono's builtins
This commit is contained in:
parent
691716f7eb
commit
69d7d50239
20 changed files with 188 additions and 174 deletions
|
|
@ -1,32 +1,5 @@
|
|||
import { config } from "~/packages/config-manager";
|
||||
|
||||
export const response = (
|
||||
data: BodyInit | null = null,
|
||||
status = 200,
|
||||
headers: Record<string, string> = {},
|
||||
) => {
|
||||
return new Response(data, {
|
||||
headers: {
|
||||
"X-Frame-Options": "DENY",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"Referrer-Policy": "no-referrer",
|
||||
"Strict-Transport-Security": "max-age=3153600",
|
||||
"X-Permitted-Cross-Domain-Policies": "none",
|
||||
"Access-Control-Allow-Credentials": "true",
|
||||
"Access-Control-Allow-Headers":
|
||||
"Authorization,Content-Type,Idempotency-Key",
|
||||
"Access-Control-Allow-Methods": "POST,PUT,DELETE,GET,PATCH,OPTIONS",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Expose-Headers":
|
||||
"Link,X-RateLimit-Reset,X-RateLimit-Limit,X-RateLimit-Remaining,X-Request-Id,Idempotency-Key",
|
||||
"Content-Security-Policy":
|
||||
"default-src 'none'; frame-ancestors 'none'; form-action 'none'",
|
||||
...headers,
|
||||
},
|
||||
status,
|
||||
});
|
||||
};
|
||||
|
||||
export type Json =
|
||||
| string
|
||||
| number
|
||||
|
|
@ -36,23 +9,6 @@ export type Json =
|
|||
| Json[]
|
||||
| { [key: string]: Json };
|
||||
|
||||
export const xmlResponse = (data: string, status = 200) => {
|
||||
return response(data, status, {
|
||||
"Content-Type": "application/xml",
|
||||
});
|
||||
};
|
||||
|
||||
export const redirect = (
|
||||
url: string | URL,
|
||||
status = 302,
|
||||
extraHeaders: Record<string, string> = {},
|
||||
) => {
|
||||
return response(null, status, {
|
||||
Location: url.toString(),
|
||||
...extraHeaders,
|
||||
});
|
||||
};
|
||||
|
||||
export const proxyUrl = (url: string | null = null) => {
|
||||
const urlAsBase64Url = Buffer.from(url || "").toString("base64url");
|
||||
return url
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue