如何在dev env中更改角度4的localhost名称以进行ssl测试?

时间:2018-01-04 20:35:03

标签: angular localhost

我正在尝试将我的托管环境而不是localhost/更改为类似www.example.com的内容。我尝试更改主机文件(sudo nano /private/etc/hosts)中的conf并执行类似下面的操作并清除我的DNS缓存dscacheutil -flushcache但不起作用。我错过了什么吗?

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
127.0.0.1       www.example.com
255.255.255.255 broadcasthost
::1             localhost
10.211.55.4     window10pro
127.0.0.1       AcronisDriveSearchPlugin

注意,我使用代理配置重定向网址调用

{
  "/api": {
     "target": "https://localhost:5001",
     "secure": false
  }
}

我的脚本以package.json

开头
"scripts": {
    "ng": "ng",
    "start": "ng serve --ssl --proxy-config proxy.config.json",....

我致电npm start来投放我的项目

1 个答案:

答案 0 :(得分:2)

刚刚在www.example.com的{​​{1}}配置中的/private/etc/hosts添加了相应的主机名(defaults),

angular-cli

并在 "defaults": { "styleExt": "scss", "serve": { "host": "www.example.com", "sslKey": "server.key", "sslCert": "server.crt" }, 中修改了我的ng start script,如下所示,

package.json

终于点击了{ "name": "quickstart-angular5", "version": "5.0.5", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve --ssl --proxy-config proxy.config.json", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "build:free": "ngm build -p src/app/typescripts/free --clean && gulp npmFree && gulp startFree && gulp onlyFree", "build:pro": "ngm build -p src/app/typescripts/pro --clean && gulp only-pro && gulp startPro", "build:all": "npm run build:free && npm run build:pro", "aot:build": "ng build --prod --sm=false --aot=true --output-path=dist", "pre-commit": "ng lint" },