This commit is contained in:
toom1996
2025-08-04 11:04:37 +08:00
parent f3092954c9
commit e2fa2c4378
90 changed files with 13749 additions and 8 deletions

34
src/middleware/index.ts Normal file
View File

@ -0,0 +1,34 @@
import { getHost } from "../../utils/host";
import { websiteConfig } from "../../utils/rpc";
export async function onRequest (context: any, next: any) {
// 拦截一个请求里的数据
// 可选地修改 `locals` 中的属性
const host = await getHost(context.request);
console.log(host)
// 防止无线跳转
if (context.locals.is_write) {
return next();
}
if (!host) {
context.locals.is_write = 1;
return context.rewrite('/404');
}
const {code, data} = await websiteConfig(host);
if (!data || code !== 0) {
context.locals.is_write = 1;
return context.rewrite('/404');
}
if (!context.locals.is_write) {
context.locals.is_write = 1;
context.locals.template_number = 2;
context.locals.template_config = data;
return context.rewrite(context.url.pathname);
}
return next();
};