fix: host addr
This commit is contained in:
parent
7a490b82df
commit
3d9617f06c
|
|
@ -204,6 +204,7 @@ export function createContentServer(
|
|||
contentDir: string,
|
||||
port: number,
|
||||
distPath: string = distDir,
|
||||
host: string = "0.0.0.0",
|
||||
): ContentServer {
|
||||
let contentIndex: ContentIndex = {};
|
||||
|
||||
|
|
@ -263,11 +264,12 @@ export function createContentServer(
|
|||
// 创建 HTTP 服务器
|
||||
const server = createServer(handleRequest);
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`\n开发服务器已启动:http://localhost:${port}`);
|
||||
server.listen(port, host, () => {
|
||||
const displayHost = host === "0.0.0.0" ? "localhost" : host;
|
||||
console.log(`\n开发服务器已启动:http://${displayHost}:${port}`);
|
||||
console.log(`内容目录:${contentDir}`);
|
||||
console.log(`静态资源目录:${distPath}`);
|
||||
console.log(`索引文件:http://localhost:${port}/__CONTENT_INDEX.json\n`);
|
||||
console.log(`索引文件:http://${displayHost}:${port}/__CONTENT_INDEX.json\n`);
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
@ -288,6 +290,7 @@ export function createContentServer(
|
|||
export const serveCommand: ServeCommandHandler = async (dir, options) => {
|
||||
const contentDir = resolve(dir);
|
||||
const port = parseInt(options.port, 10);
|
||||
const host = options.host || "0.0.0.0";
|
||||
|
||||
createContentServer(contentDir, port);
|
||||
createContentServer(contentDir, port, distDir, host);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ program
|
|||
.description('运行一个 web 服务器预览目录中的内容,并实时监听更新')
|
||||
.argument('[dir]', '要预览的目录', '.')
|
||||
.option('-p, --port <port>', '端口号', '3000')
|
||||
.option('-h, --host <host>', '主机地址', '0.0.0.0')
|
||||
.action(serveCommand);
|
||||
|
||||
program
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
export interface ServeOptions {
|
||||
port: string;
|
||||
host?: string;
|
||||
}
|
||||
|
||||
export interface CompileOptions {
|
||||
|
|
|
|||
Loading…
Reference in New Issue