/**
 * H5 开发服务器配置
 * - proxy：解决浏览器跨域
 * - host 0.0.0.0 + public：局域网同事访问时 sockjs 不连 localhost
 */
const os = require('os')

function getLanIp() {
	const nets = os.networkInterfaces()
	for (const name of Object.keys(nets)) {
		for (const net of nets[name]) {
			if (net.family === 'IPv4' && !net.internal) {
				return net.address
			}
		}
	}
	return '127.0.0.1'
}

const DEV_PORT = 8080
const LAN_IP = getLanIp()

module.exports = {
	devServer: {
		host: '0.0.0.0',
		port: DEV_PORT,
		disableHostCheck: true,
		// 热更新 websocket 使用局域网 IP，避免同事浏览器去连他们自己的 localhost
		public: `${LAN_IP}:${DEV_PORT}`,
		proxy: {
			'/api': {
				target: 'http://115.238.57.190:5200',
				changeOrigin: true,
				secure: false
			}
		}
	}
}
