mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 09:37:45 +00:00
JavaScriptServices cannot host multiple SPAs #213
Closed
opened 2025-08-09 17:15:26 +00:00 by fergalmoran
·
0 comments
No Branch/Tag Specified
master
rybrande/masterToSrc
pakrym/no-console-fb
release/2.2
pakrym/remove-obsole-api-usage
maestro/release/2.2
maestro/master
release/2.1
release/2.0
rybrande/MergeRelease21IntoDev
rel/2.0.0-extensions
angular-animations-example
fix-angular-material-publishing
rel/2.0.0-templates
httpwithstatetransfer-example
rel/2.0.0-preview2-templates
aspnet-webpack-react-2.x
angular4-prerender-data-example
version-1.x
angular2-lazy-loading-example
581-isomorphic-react-cookies-example
example-using-typescript-paths-for-494
v1.0.x
angular2-materialize-example
redux-typed-1-x
primeng-example
font-awesome-example
karma-testing-example
2.2.0
2.2.0-preview3
2.2.0-preview2
2.2.0-preview1
2.1.1
2.1.0
2.0.4
2.1.0-rc1-final
2.1.0-preview2-final
2.0.3
2.1.0-preview1-final
2.0.2
2.0.1
rel/2.0.0
rel/2.0.0-preview2
Labels
Clear labels
2 - Working
2 - Working
3 - Done
3 - Done
3 - Done
3 - Done
3 - Done
3 - Done
3 - Done
angular
angular
angular
angular
angular
bug
bug
bug
bug
bug
bug
bug
bug
bug
core
core
core
core
core
core
core
duplicate
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
external
external
P1
P1
P1
P1
P1
P1
P2
P2
P2
P2
P2
P2
P2
P2
P2
PRI: 1 - Required
react
react
task
task
up-for-grabs
up-for-grabs
up-for-grabs
waiting
waiting
waiting
waiting
No Label
Milestone
No items
No Milestone
Projects
Clear projects
No project
Assignees
fergalmoran
Clear assignees
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github/JavaScriptServices#213
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @DarthRainbows on 1/24/2018
Functional impact
I am attempting to host multiple SPA's by making multiple calls to
app.UseSpa, but whichever SPA is registered first intercepts all incoming requests.Minimal repro steps
These steps will use Angular with Angular's i18n tools to generate multiple apps, but any scenario with multiple apps should produce the same results.
dotnet new angularClientAppnpm install./ClientAppto./ClientApp2, and adjusting the build/serve scripts in thepackage.jsonfiles to deploy to different paths:./ClientApp/package.jsonscripts:./ClientApp2/package.jsonscripts:./ClientApp2/src/app/app.component.htmladd an identifier so we can differentiate the apps:./Startup.csconfigure two SPAs:dotnet runIf we disable the first call to
app.UseSpaor reverse the order, app2 loads instead of app1.Expected result
Navigating to the base path of an SPA should route to that specific SPA.
Actual result
Whichever SPA is configured first handles all requests.
Further technical details
While I am a newcomer to .Net Core MVC/Javascript services, from what I can tell so far, it looks like the SPA configuration needs an option to specify a route to handle requests for.
Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.Attachrewrites all requests to point tooptions.DefaultPage, which is then either handled by the middleware attached byapp.UseSpaStaticFilesInternalor caught by an error handler. In my example, a request coming in to /app2 gets pointed to/app1/index.html, which is served up by the static file middleware for app1, and so never gets to the middleware configured by the second call toapp.UseSpa.Overriding the default file provider (as suggested in code comments) doesn't help, because the request path is still being overwritten, so we can't distinguish the apps at the file provider. Even if we could, the request would be caught by the error handler before it could get to the middleware configured for the second SPA.
The path rewrite and the error handler need to be aware of the SPA base path, so requests can pass to the appropriate apps. Perhaps something akin to the way routing is handled in .Net Core MVC?