This commit is contained in:
2025-12-29 01:34:06 +08:00
parent ff7e6aa152
commit 91409861b9
5 changed files with 41 additions and 16 deletions

View File

@@ -10,6 +10,15 @@ import WebSocket from 'ws';
const localProxy = new LocalProxy({});
localProxy.initFromAssistantConfig(assistantConfig);
const isOpenPath = (pathname: string): boolean => {
const openPaths = ['/root/home', '/root/cli'];
for (const openPath of openPaths) {
if (pathname.startsWith(openPath)) {
return true;
}
}
return false;
}
/**
* 过滤访问的资源,允许谁访问
* @param req
@@ -108,6 +117,7 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
target: apiBackendProxy.target,
});
}
logger.debug('proxyRoute handle by router', { url: req.url }, noAdmin);
const urls = pathname.split('/');
const [_, _user, _app] = urls;
if (!_app) {
@@ -115,7 +125,9 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
res.end('Not Found Proxy');
return;
}
if (noAdmin) {
const isOpen = isOpenPath(pathname)
log.debug('proxyRoute', { _user, _app, pathname, noAdmin, isOpen });
if (noAdmin && !isOpen) {
return toSetting();
}
if (_app && urls.length === 3) {