From f24c0d207861b9afcba7c5c2e092b404e4dec404 Mon Sep 17 00:00:00 2001 From: monoid Date: Fri, 21 Apr 2023 17:31:07 +0900 Subject: [PATCH] add CORS support --- src/login.ts | 2 +- src/server.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/login.ts b/src/login.ts index 724205c..291fb7f 100644 --- a/src/login.ts +++ b/src/login.ts @@ -267,7 +267,7 @@ export const resetPasswordMiddleware = (cntr: UserAccessor) => } export function createLoginRouter(userController: UserAccessor) { - let router = new Router(); + const router = new Router(); router.post('/login', createLoginMiddleware(userController)); router.post('/logout', LogoutMiddleware); router.post('/refresh', createRefreshTokenMiddleware(userController)); diff --git a/src/server.ts b/src/server.ts index 66ce27e..0cda10d 100644 --- a/src/server.ts +++ b/src/server.ts @@ -64,6 +64,11 @@ class ServerApplication{ let diff_router = createDiffRouter(this.diffManger); this.diffManger.register("comic",createComicWatcher()); let router = new Router(); + router.use("/api/*", async (ctx,next)=>{ + //For CORS + ctx.res.setHeader("access-control-allow-origin", "*"); + await next(); + }); router.use('/api/diff',diff_router.routes()); router.use('/api/diff',diff_router.allowedMethods()); @@ -77,8 +82,8 @@ class ServerApplication{ router.use('/api/doc',content_router.allowedMethods()); const tags_router = getTagRounter(this.tagController); - router.use("/api/tags",tags_router.routes()); router.use("/api/tags",tags_router.allowedMethods()); + router.use("/api/tags",tags_router.routes()); const login_router = createLoginRouter(this.userController); router.use('/user',login_router.routes());