-
Notifications
You must be signed in to change notification settings - Fork 12k
Confused about actual webroot with "ng serve", *.bundle.js not loading #4226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@alpengeist can you try to run |
I've tried that. Same result. The build was never the problem in the first place. The files are at the right place under dist/. The --base-ref modified index.html, which I had done manually. Thus, it is all the same. The webserver configuration of ng serve is the confusing bit. I know it is webpack, but what is its configuration? Why is everything behind 4200/ irrelevant and index.html gets opened no matter what? It seems as if it has a default fallback rule built-in. Moreover, ng serve runs a build but the files appear nowhere. It won't write into dist/. |
@alpengeist This isn't an answer to your question, but one oddity I discovered is that for me when I changed the href on my tag from However, it's loading them from the root URL, which is strange. E.g. I'm also trying to setup a proxy to route everything through port 80 (using Apache) but without any luck. Using other static file servers works fine except for the angular routes, which is why I'm trying to get |
The way I got this working is by running The bad news is that this is not supported in In my case, I serve the I use |
I got it working! One thing I thought you might try to get I created a JSON file
(The config is inspired by examples from Webpack docs linked in the Angular CLI proxy section) And ensured the base href is set correctly in my
Then ran
It worked just fine including routing, even lazy loading. One thing to beware of though is that For production you need to bring your own server and use it with |
Here's my working example source code: https://github.com/Meligy/routing-angular-cli/tree/custom-base-path Look at this commit specifically Meligy/routing-angular-cli@eee45cf Check the |
@Meligy This is great, thank you so much! I got away without the -bh option by synchronizing the outDir in I know that ng serve is just for development, but I wanted it to work with the same project config, which is now fixed with the proxy option. And thank you also for the last bit for me to understand the router. The reroute to index.html is the detail that I was missing. It occured to me this morning and you confirmed it. Funny that this is not prominently explained in the router manual. |
Awesome writeup by @Meligy, adding this to the FAQs! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
OS?
Versions.
Repro steps.
Hi,
I got stuck and I hope you could help me out.
I started out normally with the CLI and then decided to put the app behind a proxy. The proxy must distribute requests to various services, all under a common origin. For that, I needed to add a web root prefix to the app, which ran under 4200/ as per default. The app should run under 4200/monitoring/ui so that the proxy can route everything under 80/monitoring/ui to 4200/monitoring/ui
I did the following:
index.html: changed base href from "/" to "/monitoring/ui/"
.angular-cli.json: "outDir": "dist/monitoring/ui"
The build worked ok. Now, with ng serve running, http://localhost:4200/monitoring/ui will open, but all the .bundle.js files get a 404. I noticed that it is totally irrelevant what I type behind 4200, index.html will always open.
With an external http server sitting on ./dist instead of ng serve the app starts fine, but the angular router won't work anymore.
I don't understand where ng serve actually has its web root and how this is intertwined with the angular router.
Thanks!
The log given by the failure.
Mention any other details that might be useful.
The text was updated successfully, but these errors were encountered: