This commit is contained in:
toom1996
2025-06-24 19:04:53 +08:00
parent 375244d58b
commit a7cc06cefc
7 changed files with 1404 additions and 0 deletions

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

@ -0,0 +1,39 @@
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);
if (host == 'www.zhishihuisheng.com' || host == 'zhishihuisheng.com') {
return next();
}
// 防止无线跳转
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 = 1;
context.locals.template_config = data;
return context.rewrite('/template/' + context.locals.template_number + context.url.pathname);
}
return next();
};