mirror of https://github.com/msgbyte/tailchat
feat: 桌面版增加方案,通过本地http服务器来展示页面
parent
f9c0776267
commit
5fcc8264d9
@ -0,0 +1,29 @@
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* 启动一个本地服务器
|
||||
*/
|
||||
export function startLocalServer(
|
||||
staticPath: string,
|
||||
port: number
|
||||
): Promise<void> {
|
||||
return new Promise<void>((resolve) => {
|
||||
const app = express();
|
||||
|
||||
const staticDir = path.resolve(__dirname, staticPath);
|
||||
console.log('Static File:', staticDir);
|
||||
|
||||
app.use(express.static(staticDir));
|
||||
|
||||
// Fallback
|
||||
app.use('/**', function (_, res) {
|
||||
res.sendFile(staticPath + '/index.html', { maxAge: 0 });
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log('Static file server is listen at:', port);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue