支持CROS

This commit is contained in:
Sirius
2026-08-05 17:37:41 +08:00
parent 7dd16e370f
commit bd18678963
4 changed files with 24 additions and 5 deletions
+8
View File
@@ -33,6 +33,14 @@ export async function createServer(config: BridgeConfig): Promise<BridgeServer>
});
const coordinator = new RequestCoordinator();
app.addHook("onRequest", async (_request, reply) => {
reply.raw.setHeader("Access-Control-Allow-Origin", "*");
reply.raw.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
reply.raw.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
});
app.options("/*", async (_request, reply) => reply.status(204).send());
app.setErrorHandler((error, _request, reply) => {
const fastifyError = error as Error & { code?: string; statusCode?: number };
if (fastifyError.code === "FST_ERR_CTP_BODY_TOO_LARGE") {