angular8让同事通过局域网访问你的项目

1.找到这个文件,打开

node_modules/webpack-dev-server/lib/Server.js

2.修改disallow=true
就像下面这个样子

Server.prototype.checkHost = function(headers) {
     
 // allow user to opt-out this security check, at own risk
 if(this.disableHostCheck) return true;

 // get the Host header and extract hostname
 // we don't care about port not matching
 const hostHeader = headers.host;
 if(!hostHeader) return false;
 const idx = hostHeader.indexOf(":");
 const hostname = idx >= 0 ? hostHeader.substr(0, idx) : hostHeader;

 // always allow localhost host, for convience
 if(hostname === "127.0.0.1" || hostname === "localhost") return true;

 // allow hostname of listening adress
 if(hostname === this.listenHostname) return true;

 // also allow public hostname if provided
 if(typeof this.publicHost === "string") {
     
  const idxPublic = this.publicHost.indexOf(":");
  const publicHostname = idxPublic >= 0 ? this.publicHost.substr(0, idxPublic) : this.publicHost;
  if(hostname === publicHostname) return true;
 }

 // disallow
 return true;
}

3.启动项目,使用下面指令(后面那个是你自己的IP)

ng serve --host 10.222.222.222

O 啦~

你可能感兴趣的:(angular8让同事通过局域网访问你的项目)