update: add local-proxy library

This commit is contained in:
2025-06-20 12:07:09 +08:00
parent 3c0cb64478
commit 574317a42d
14 changed files with 361 additions and 133 deletions

View File

@@ -1,16 +1,15 @@
import { fileProxy, httpProxy, createApiProxy, wsProxy } from '@/module/assistant/index.ts';
import http from 'http';
import http from 'node:http';
import { LocalProxy } from './local-proxy.ts';
import { assistantConfig, app } from '@/app.ts';
import { log, logger } from '@/module/logger.ts';
const localProxy = new LocalProxy({
assistantConfig,
});
const localProxy = new LocalProxy({});
localProxy.initFromAssistantConfig(assistantConfig);
export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResponse) => {
const _assistantConfig = assistantConfig.getCacheAssistantConfig();
const appDir = assistantConfig.configPath?.pagesDir;
const url = new URL(req.url, 'http://localhost');
const pathname = url.pathname;
const pathname = decodeURIComponent(url.pathname);
if (pathname === '/' && _assistantConfig?.home) {
res.writeHead(302, { Location: `${_assistantConfig?.home}/` });
return res.end();
@@ -71,7 +70,7 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
log.log('localProxyProxy', { localProxyProxy, url: req.url });
return fileProxy(req, res, {
path: localProxyProxy.path,
rootPath: appDir,
rootPath: localProxy.pagesDir,
indexPath: localProxyProxy.indexPath,
});
}