Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在用于ssl测试的dev env中更改angular 4的本地主机名?_Angular_Localhost - Fatal编程技术网

如何在用于ssl测试的dev env中更改angular 4的本地主机名?

如何在用于ssl测试的dev env中更改angular 4的本地主机名?,angular,localhost,Angular,Localhost,我正在尝试将我的主机环境更改为类似www.example.com的内容,而不是localhost/。我试图更改主机文件(sudo nano/private/etc/hosts)中的配置,并执行如下操作,然后清除我的DNS缓存dscacheutil-flushcache,但没有成功。我错过什么了吗 ## # Host Database # # localhost is used to configure the loopback interface # when the system is boo

我正在尝试将我的主机环境更改为类似www.example.com的内容,而不是
localhost/
。我试图更改主机文件(
sudo nano/private/etc/hosts
)中的配置,并执行如下操作,然后清除我的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
注意,我使用代理配置重定向url调用

{
  "/api": {
     "target": "https://localhost:5001",
     "secure": false
  }
}
我的脚本从
package.json

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

我调用
npm start
为我的项目提供服务

刚刚在
angular cli
中的
默认值中的
配置中的
/private/etc/hosts
中添加了相应的主机名(
www.example.com

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

{
  "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"
  },

最后点击
npm start

这是在调用
ng service
时发生的吗?如果是这样,默认情况下它只在
localhost
上侦听。请看一些解决方案