website-client-Nigeria/scripts/dev.js

33 lines
869 B
JavaScript

#!/usr/bin/env node
const { spawn } = require('child_process');
const os = require('os');
// 获取本机 IP 地址
function getLocalIP() {
const interfaces = os.networkInterfaces();
for (const name of Object.keys(interfaces)) {
for (const interface of interfaces[name]) {
if (interface.family === 'IPv4' && !interface.internal) {
return interface.address;
}
}
}
return 'localhost';
}
const localIP = getLocalIP();
console.log(`🚀 启动开发服务器...`);
console.log(`📱 本机访问: http://localhost:1110`);
console.log(`🌐 内网访问: http://${localIP}:1110`);
// 启动 Nuxt 开发服务器
const child = spawn('npx', ['nuxt', 'dev', '--host', '0.0.0.0', '--port', '1110'], {
stdio: 'inherit',
shell: true
});
child.on('close', (code) => {
console.log(`开发服务器已停止,退出码: ${code}`);
});