From d9ceda09c8e03e63c352f942d839c2d046cbc976 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 15 Dec 2020 20:10:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0linux=20server=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=B8=8B=E8=B0=83=E8=AF=95zhic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vue.config.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/vue.config.js b/vue.config.js index 7b9d2db..6a5efcc 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,12 +1,27 @@ 'use strict' const path = require('path') const pkg = require('./package.json') +const os = require('os') function resolve(dir) { return path.join(__dirname, dir) } +function getIPAdress() { + let interfaces = os.networkInterfaces() + for (let devName in interfaces) { + let iface = interfaces[devName] + for (let i = 0; i < iface.length; i++) { + let alias = iface[i] + if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) { + return alias.address + } + } + } +} + const name = pkg.name || 'vue-element-admin' // page title +const host = getIPAdress() const port = 9527 // dev port // All configuration item explanations can be find in https://cli.vuejs.org/config/ @@ -24,6 +39,7 @@ module.exports = { lintOnSave: process.env.NODE_ENV === 'development' ? 'error' : false, productionSourceMap: false, devServer: { + host: host, port: port, open: true, overlay: { @@ -34,7 +50,7 @@ module.exports = { // change xxx-api/login => mock/login // detail: https://cli.vuejs.org/config/#devserver-proxy [process.env.VUE_APP_BASE_API]: { - target: `http://localhost:${port}/mock`, + target: `http://${host}:${port}/mock`, changeOrigin: true, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: ''