2

I'm running Angular 5 and had to, according to the env build, change the index.html. So I went with multiple "apps":declaration inside angular-cli.json, where --app=0 has dev envs and --app=1 has prod envs.
The --app=1 has "index": "index.prod.html".
When I deploy and go my domain I get: enter image description here

I'm using nginx and my default.conf has

server {
    ...
    root   /usr/share/nginx/html;

    location / {
        autoindex on;
        try_files $uri $uri/ /index.html;
        index  index.html index.htm;
    }
    ...
}

And I came across the thought that nginx is failing to get my proper index.html that is named as index.prod.html (as seen inside my dist folder), and falling to nginx.html.
The problem I'm running through is that I need to support index.html and index.prod.html, cause I have different envs and I can deploy them as well.

How can I achieve that? Thanks.

João Ghignatti
  • 2,281
  • 1
  • 13
  • 25
  • If all possible would be easier if you upgrade to angular 6+, there is a new `angular.json` config that has something that could potentially solve your issue. In angular 6+ there a config under `configurations` called `fileReplacements` which you can set per env – penleychan Dec 11 '18 at 18:38
  • Hi, thanks for your answer. I know that upgrading would solve all my problems, but I can't do it right now, considering this is a huge level app. I kinda have to solve this with what I have right now. – João Ghignatti Dec 11 '18 at 18:39
  • It would solve your issue, and you'll have to upgrade at some point. The sooner, the simpler. – JB Nizet Dec 11 '18 at 18:44
  • Try to change two lines of your config into `try_files $uri $uri/ /index.prod.html /index.html;` and `index index.prod.html index.html;`. – Ivan Shatsky Dec 11 '18 at 19:01

1 Answers1

0

I'm running Angular 8.0

|__src/ |__index.html |__index/ |__prod/ |index.html |***/ |__index.html

Config in angular.json

"configurations": { "prod": {

          "index": "src/index/prod/index.html",              
         
        },

Modify build scripts in package.json

"scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "build:prod": "ng build --prod" }