feat: 更新开发脚本,添加新的环境变量支持,优化管理员登录流程
This commit is contained in:
@@ -50,6 +50,9 @@ export class AssistantInit extends AssistantConfig {
|
||||
}
|
||||
return this.#query;
|
||||
}
|
||||
get baseURL() {
|
||||
return `${this.getConfig()?.pageApi || 'https://kevisual.cn'}/api/router`;
|
||||
}
|
||||
setQuery(query?: Query) {
|
||||
this.#query = query || new Query({
|
||||
url: `${this.getConfig()?.pageApi || 'https://kevisual.cn'}/api/router`,
|
||||
|
||||
@@ -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}/` });
|
||||
|
||||
Reference in New Issue
Block a user