angular6允許局域網可訪問

打開node_modules/webpack-dev-server/lib/Server.js文件
1:修改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;
}

2、啓動時候,使用ng serve —host 0.0.0.0

問題解決。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章