mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: allowCors option for Handler
This commit is contained in:
1 parent
c347d36e99
commit
cafe9246c2
2 files changed
+10
-9
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { CsrfTokenError, NotFoundError } from '../../error';
|
||||
import { NotFoundError } from '../../error';
|
||||
import avatar from '../../lib/avatar';
|
||||
import { PERM } from '../../model/builtin';
|
||||
import UserModel from '../../model/user';
|
||||
@@ -6,7 +6,7 @@ import type { KoaContext } from '../server';
|
||||
|
||||
export default async (ctx: KoaContext, next) => {
|
||||
// User Layer
|
||||
const { request, args, domain } = ctx.HydroContext;
|
||||
const { args, domain } = ctx.HydroContext;
|
||||
const domainId = domain ? args.domainId : 'system';
|
||||
let user = await UserModel.getById(domainId, ctx.session.uid, ctx.session.scope);
|
||||
if (!user) {
|
||||
@@ -21,9 +21,5 @@ export default async (ctx: KoaContext, next) => {
|
||||
ctx.pendingError = new NotFoundError(args.domainId);
|
||||
args.domainId = 'system';
|
||||
}
|
||||
if (request.method === 'post' && request.headers.referer && !ctx.cors) {
|
||||
const host = new URL(request.headers.referer).host;
|
||||
if (host !== request.host) ctx.pendingError = new CsrfTokenError(host);
|
||||
}
|
||||
await next();
|
||||
};
|
||||
Reference in new issue
Block a user