fix localproxy add watch
This commit is contained in:
parent
1e340ec2b3
commit
a5168d33ca
@ -21,7 +21,7 @@
|
||||
"scripts": {
|
||||
"dev": "bun run src/run.ts ",
|
||||
"dev:server": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 bun --watch src/run-server.ts ",
|
||||
"dev:share": "bun --watch src/test/remote-app.ts ",
|
||||
"dev:share": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 bun --watch src/test/remote-app.ts ",
|
||||
"build:lib": "bun run bun-lib.config.mjs",
|
||||
"postbuild:lib": "dts -i src/lib.ts -o assistant-lib.d.ts -d libs -t",
|
||||
"build": "rimraf dist && bun run bun.config.mjs",
|
||||
|
@ -1,27 +1,7 @@
|
||||
import fs from 'node:fs';
|
||||
import { AssistantConfig, checkFileExists } from '@/module/assistant/index.ts';
|
||||
import path from 'node:path';
|
||||
|
||||
export const localProxyProxyList = [
|
||||
{
|
||||
user: 'root',
|
||||
key: 'assistant-base-app',
|
||||
path: '/root/assistant-base-app',
|
||||
indexPath: 'root/assistant-base-app/index.html',
|
||||
},
|
||||
{
|
||||
user: 'root',
|
||||
key: 'talkshow-admin',
|
||||
path: '/root/talkshow-admin',
|
||||
indexPath: 'root/talkshow-admin/index.html',
|
||||
},
|
||||
{
|
||||
user: 'root',
|
||||
key: 'center',
|
||||
path: '/root/center',
|
||||
indexPath: 'root/center/index.html',
|
||||
},
|
||||
];
|
||||
import { logger } from '@/module/logger.ts';
|
||||
|
||||
type ProxyType = {
|
||||
user: string;
|
||||
@ -43,8 +23,12 @@ export class LocalProxy {
|
||||
constructor(opts?: LocalProxyOpts) {
|
||||
this.assistantConfig = opts?.assistantConfig;
|
||||
if (this.assistantConfig) {
|
||||
this.watch = !!this.assistantConfig.config?.watch.enabled;
|
||||
this.watch = !!this.assistantConfig.getCacheAssistantConfig()?.watch.enabled;
|
||||
this.init();
|
||||
console.log('init local proxy', this.assistantConfig.getAppList);
|
||||
if (this.watch) {
|
||||
this.onWatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
init() {
|
||||
@ -72,7 +56,7 @@ export class LocalProxy {
|
||||
localProxyProxyList.push({
|
||||
user: user,
|
||||
key: app,
|
||||
path: `/${user}/${app}`,
|
||||
path: `/${user}/${app}/`,
|
||||
indexPath: `${user}/${app}/index.html`,
|
||||
absolutePath: appPath,
|
||||
});
|
||||
@ -102,15 +86,17 @@ export class LocalProxy {
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
fn();
|
||||
logger.info('reload local proxy');
|
||||
}, delay);
|
||||
};
|
||||
fs.watch(frontAppDir, { recursive: true }, (eventType, filename) => {
|
||||
if (eventType === 'change') {
|
||||
if (eventType === 'rename' || eventType === 'change') {
|
||||
const filePath = path.join(frontAppDir, filename);
|
||||
try {
|
||||
const stat = fs.statSync(filePath);
|
||||
if (stat.isDirectory()) {
|
||||
debounce(that.init, 5000);
|
||||
if (stat.isDirectory() || filename.endsWith('.html')) {
|
||||
// 重新加载
|
||||
debounce(that.init.bind(that), 5 * 1000);
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user