Files
cnb/agent/routes/index.ts
2026-01-12 03:18:09 +08:00

36 lines
715 B
TypeScript

import { app, appId } from '@/agent/app.ts';
import './user/check.ts'
const checkAppId = (ctx: any, appId: string) => {
const _appId = ctx?.appId;
if (_appId) {
if (_appId !== appId) {
ctx.throw(403, 'Invalid App ID');
}
return true;
}
return false;
}
if (!app.hasRoute('auth')) {
app.route({
id: 'auth',
path: 'auth',
}).define(async (ctx) => {
// ctx.body = 'Auth Route';
if (checkAppId(ctx, appId)) {
return;
}
}).addTo(app);
app.route({
id: 'admin-auth',
path: 'admin-auth',
middleware: ['auth'],
}).define(async (ctx) => {
// ctx.body = 'Admin Auth Route';
if (checkAppId(ctx, appId)) {
return;
}
}).addTo(app);
}