update
This commit is contained in:
@@ -197,6 +197,7 @@ export const postProxy = async (req: IncomingMessage, res: ServerResponse, opts:
|
||||
fileSize: 100 * 1024 * 1024, // 100MB
|
||||
files: 1,
|
||||
},
|
||||
defCharset: 'utf-8',
|
||||
});
|
||||
let fileProcessed = false;
|
||||
bb.on('file', async (name, file, info) => {
|
||||
|
||||
@@ -58,7 +58,9 @@ export class WsProxyManager {
|
||||
value.ws.close();
|
||||
}
|
||||
}
|
||||
console.log('WsProxyManager register', id);
|
||||
const [username, appId] = id.split('-');
|
||||
const url = new URL(`/${username}/v1/${appId}`, 'https://kevisual.cn/');
|
||||
console.log('WsProxyManager register', id, '访问地址', url.toString());
|
||||
const value = new WsMessage({ ws: opts?.ws, user: opts?.user });
|
||||
this.wssMap.set(id, value);
|
||||
}
|
||||
|
||||
@@ -10,12 +10,16 @@ type ProxyOptions = {
|
||||
};
|
||||
export const UserV1Proxy = async (req: IncomingMessage, res: ServerResponse, opts?: ProxyOptions) => {
|
||||
const { url } = req;
|
||||
const { pathname } = new URL(url || '', `http://localhost`);
|
||||
const _url = new URL(url || '', `http://localhost`);
|
||||
const { pathname, searchParams } = _url;
|
||||
let [user, app, userAppKey] = pathname.split('/').slice(1);
|
||||
if (!user || !app || !userAppKey) {
|
||||
opts?.createNotFoundPage?.('应用未找到');
|
||||
return false;
|
||||
}
|
||||
if (!userAppKey.includes('-')) {
|
||||
userAppKey = user + '-' + userAppKey;
|
||||
}
|
||||
|
||||
const data = await App.handleRequest(req, res);
|
||||
const loginUser = await getLoginUser(req);
|
||||
@@ -43,6 +47,14 @@ export const UserV1Proxy = async (req: IncomingMessage, res: ServerResponse, opt
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const path = searchParams.get('path');
|
||||
if (!path) {
|
||||
// 显示前端页面
|
||||
const html = fetch('https://kevisual.cn/root/router-studio/index.html').then(res => res.text());
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' });
|
||||
res.end(await html);
|
||||
return true;
|
||||
}
|
||||
const value = await client.sendData(data);
|
||||
if (value) {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
|
||||
Reference in New Issue
Block a user