0

I am using angular-cli with built-in webpack and encounter the following problem: if I use ng serve --host 0.0.0.0 --port 3000 everything works fine, but when I try to build the app (no matter developer mode or production) with ng build and then put it into my nginx, not a single route works and every attempt of browser to download image, which is used on start page, ends with 404 error. What am I doing wrong? Googled a ton of stuff and nothing seems to be a solution.

Some additional info:

angular-cli: 1.0.0-beta.21
node: 6.9.4
os: win32 x64
Leonid Bor
  • 2,064
  • 6
  • 27
  • 47
  • are you sure you have nginx configured correctly? – shusson Jan 29 '17 at 11:07
  • have you tried to serve a minimal `index.html` file with nginx? – shusson Jan 29 '17 at 11:17
  • @shusson it seems like nginx is trying to find corresponding files inside the folder of an app, but instead there are only `index.html` and `main.bundle.js`, because that's how `webpack` builds an app. Is there any solution for this available? – Leonid Bor Jan 29 '17 at 15:17
  • an `index.html` file is all nginx needs. You should look up how Single Page Applications work. Maybe try using a different server like pythons SimpleHttpServer. – shusson Jan 29 '17 at 22:59

1 Answers1

0

So for everyone who encounters this problem, after some research I found this:

1) To solve problem with styles not loading properly, add encapsulation: ViewEncapsulation.None to each of your components @Component() decorator, this way it's going to bundle styles properly. More info here: https://angular.io/docs/ts/latest/guide/component-styles.html#!#loading-styles

2) Make sure all your images are stored inside assets folder. If you store them in some other folder like images, just put that images folder inside assets

3) And for information about paths not working on page reload, have a look at this question and read some information about strategies: Angular 2 : 404 error occur when i refresh through Browser Also this link has config examples https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

Community
  • 1
  • 1
Leonid Bor
  • 2,064
  • 6
  • 27
  • 47