2

I am trying to change my hosting env instead of localhost/ to something like www.example.com. I tried to change the the conf in my hosts file (sudo nano /private/etc/hosts) and doing something like below and clear my DNS cache dscacheutil -flushcache but did not work. am I missing something?

##
# 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

Note, I am using proxy config to redirect the url calls,

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

and I my script start in package.json

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

I call npm start to serve my project

JSON
  • 1,583
  • 4
  • 31
  • 63
  • 1
    Is this when calling `ng serve`? If so, it only listens on `localhost` by default. Have a look at https://stackoverflow.com/questions/37762125/set-default-host-and-port-for-ng-serve-in-config-file for some solutions – user184994 Jan 04 '18 at 20:37

1 Answers1

4

just added the corresponding hostname (www.example.com) in my /private/etc/hosts in the defaults config in angular-cli,

 "defaults": {
    "styleExt": "scss",
    "serve": {
      "host": "www.example.com",
      "sslKey": "server.key",
      "sslCert": "server.crt"
    },

and modified my ng start script in package.json as below,

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

finally hit npm start

JSON
  • 1,583
  • 4
  • 31
  • 63