add CORS support

This commit is contained in:
monoid 2023-04-21 17:31:07 +09:00
parent b8cbcb74ef
commit f24c0d2078
2 changed files with 7 additions and 2 deletions

View File

@ -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));

View File

@ -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());