angular-cli
angular-cli copied to clipboard
Angular SSR: Express routes are only prefixed in development with baseHref set
Command
serve
Is this a regression?
- [ ] Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
When setting the baseHref, all dev server requests are required to be prefixed, even if I have routes in my server.ts that do not need the baseHref, such as health check endpoints.
Then when building the application the endpoint works without the baseHref, causing a mismatch of behavior between dev and build.
Minimal Reproduction
https://github.com/brandonroberts/angular-ssr-base-href
- Clone the repo
- Run npm install
- Run npm start
- Visit
http://localhost:4200/ping - Note the error message that the URL should be
http://localhost:4200/custom/ping - Stop the dev server
- Run npm run build
- Run
npm run serve:ssr:angular-ssr-base-href - Visit
http://localhost:4000/ping - Note the route displays correctly
Exception or Error
Your Environment
Angular: 20.3.12
... common, compiler, compiler-cli, core, forms
... platform-browser, platform-server, router
Package Version
------------------------------------
@angular-devkit/architect 0.2003.10
@angular-devkit/core 20.3.10
@angular-devkit/schematics 20.3.10
@angular/build 20.3.10
@angular/cli 20.3.10
@angular/ssr 20.3.10
@schematics/angular 20.3.10
rxjs 7.8.2
typescript 5.9.3
zone.js 0.15.1
Anything else relevant?
Tested with Angular v21 also