1

I'm using ASP.NET Core 6. I have multiple apps:

uri user tech
www.example.com visitors (landing pages, products,
about us, contacts, etc.)
razor pages
api.example.com - webapi (to support blazor apps)
app.example.com customers blazor wasm
staff.example.com staff blazor wasm

I wanted everything in one server app - which is possible, but complicated; I managed to get some of it working. There are many questions (here and in the aspnet repo) for this approach - its popular because deployment seems simple and self-contained (but many people struggle with this, and many questions don't even have working answers).

I realised that even if I succeed, there are many moving parts (the config is a nightmare!), many things that could break in production, and someone else might have to maintain it.

So maybe it's better to have separate (dockerised) apps.

Pros:

  • simpler implementation
  • simpler maintenance
  • easier to scale (especially read-heavy apps, e.g. www and blazor apps, which could even be moved to a CDN)
  • better division of labour (different team members responsible for different apps)
  • from personal experience the "www" public website changes more often (sometimes daily) than the "api" web app, so pushing changes to production requires updating everything - whereas if separate then one only pushes changes to individual apps
  • easier to isolate faults: if something fails or must be taken down for maintenance, the problem is localised and other parts of the system continue to function

Cons:

  • complicated deployment
  • more monitoring and health checks
  • ...?

If you've dealt with this, in production, please share your experience. I've no idea what to expect.

I'm interested in the core problem: is serving everything from one server app asking for trouble, or is it a worthy (and maintainable) goal? Thanks!

lonix
  • 14,255
  • 23
  • 85
  • 176
  • I guess you could build multiple `Startup` classes for your views / api's, picking one based on an environment variable? Or `.Map` endpoints based on host? But from the web server's POV blazor is just static files. – Jeremy Lakeman Apr 26 '22 at 04:16
  • @JeremyLakeman Thanks. Yep there are a number of ways to do it, another good option is splitting the pipeline based on incoming port or subdomain (that's how I did it). Still, keeping multiple apps in a single "hosting" server app gets tricky quite quickly. It's appealing at face value, but I fear long-term maintenance will be complicated. – lonix Apr 26 '22 at 04:20
  • It's also possible to configure multiple auth schemes, for multiple auth policies, and apply them to different endpoints. It's ultimately the `Startup` / application builder that brings everything together. Though you might want to shift any page / api specific config into separate helper methods, or at least `#region`. To ensure it's obvious why each line is there. – Jeremy Lakeman Apr 26 '22 at 04:27

1 Answers1

1

The answer is yes. While the core web server config is more complicated, you only really have one site.

  • The razor pages and API are standard server side code that can co-exist on the same site. You can apply whatever authentication schemes to them you wish.

  • The two WASM sites only need a web server to serve up their startup files. After that I assume it's all API calls back to the server.

There's an answer I wrote a few months ago with a Repo that explains how to set up a server to serve two WASM sites. Create a multiple WebAssembly projects in a single solution

There's also a couple of articles on Codeproject describing how to do it - search "CodeProject HYDRA".

MrC aka Shaun Curtis
  • 19,075
  • 3
  • 13
  • 31
  • Thanks for your advice! A **major** benefit, as you've mentioned, everything is self-contained. But there are drawbacks too, as I've listed above. Also, from past experience the "www" website changes more often (sometimes daily) than the "api" web app, and pushing changes to production requires updating everything - whereas if separate then one only pushes changes to individual apps. Also I imagine if something fails, the problem is localised and other parts of the system continue to function. – lonix Apr 26 '22 at 08:30
  • That sample is very helpful, thanks! – lonix Apr 26 '22 at 08:31
  • NP. You now know how to do it. But it's your application, and your decision. :-) – MrC aka Shaun Curtis Apr 26 '22 at 13:21