mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { APActivity, APObject } from "activitypub-types";
|
|
import { NodeObject } from "jsonld";
|
|
|
|
export const jsonResponse = (
|
|
data: object,
|
|
status = 200,
|
|
headers: Record<string, string> = {}
|
|
) => {
|
|
return new Response(JSON.stringify(data), {
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"X-Frame-Options": "DENY",
|
|
"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",
|
|
...headers,
|
|
},
|
|
status,
|
|
});
|
|
};
|
|
|
|
export const xmlResponse = (data: string, status = 200) => {
|
|
return new Response(data, {
|
|
headers: {
|
|
"Content-Type": "application/xml",
|
|
},
|
|
status,
|
|
});
|
|
};
|
|
|
|
export const jsonLdResponse = (
|
|
data: NodeObject | APActivity | APObject,
|
|
status = 200
|
|
) => {
|
|
return new Response(JSON.stringify(data), {
|
|
headers: {
|
|
"Content-Type": "application/activity+json",
|
|
},
|
|
status,
|
|
});
|
|
};
|
|
|
|
export const errorResponse = (error: string, status = 500) => {
|
|
return jsonResponse(
|
|
{
|
|
error: error,
|
|
},
|
|
status
|
|
);
|
|
};
|