feat: 更新开发脚本,添加新的环境变量支持,优化管理员登录流程

This commit is contained in:
2025-12-18 03:47:07 +08:00
parent 5b610fd600
commit 6e1ffe173a
6 changed files with 91 additions and 34 deletions

View File

@@ -8,15 +8,21 @@ localProxy.initFromAssistantConfig(assistantConfig);
export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResponse) => {
const _assistantConfig = assistantConfig.getCacheAssistantConfig();
const auth = _assistantConfig?.auth;
if (!auth.username) {
const home = _assistantConfig?.home || '/root/home';
const auth = _assistantConfig?.auth || {};
let noAdmin = !auth.username;
const toSetting = () => {
res.writeHead(302, { Location: `/root/cli/setting/` });
return res.end();
res.end();
return true;
}
const url = new URL(req.url, 'http://localhost');
const pathname = decodeURIComponent(url.pathname);
if (pathname === '/' && _assistantConfig?.home) {
res.writeHead(302, { Location: `${_assistantConfig?.home}/` });
if (pathname === '/') {
if (noAdmin) {
return toSetting();
}
res.writeHead(302, { Location: `${home}/` });
return res.end();
}
if (pathname.startsWith('/favicon.ico')) {
@@ -25,8 +31,7 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
return;
}
if (pathname.startsWith('/client')) {
logger.info('url', { url: req.url });
console.debug('handle by router');
logger.debug('handle by router', { url: req.url });
return;
}
// client, api, v1, serve 开头的拦截
@@ -47,6 +52,9 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
res.end('Not Found Proxy');
return;
}
if (noAdmin) {
return toSetting();
}
if (_app && urls.length === 3) {
// 重定向到
res.writeHead(302, { Location: `${req.url}/` });