question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple spa with multitenant

See original GitHub issue

I am looking to redirect to an admin spa when tenant is null, otherwise redirect to user spa

app.Map("/admin",
   adminApp =>
   {
     adminApp.UseSpa(spa =>
     {
       spa.Options.SourcePath = "angular/admin";
       spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
       {
           FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "angular", "admin"))
       };

       if (env.IsDevelopment())
         spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
      });
    });

  app.Map("/user",
    userApp =>
    {
      userApp.UseSpa(spa =>
      {
        spa.Options.SourcePath = "angular/user";
        spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "angular", "user"))
        };

        if (env.IsDevelopment())
          spa.UseProxyToSpaDevelopmentServer("http://localhost:4201");
      });
  });  

In the code used by routes, I try to do it through the tenantInfo, is it possible to do it or would there be a better way? Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
AndrewTriesToCodecommented, Sep 30, 2021

Thanks for the repo. It seems this approach for SPA has been deprecated but I think you can still get this to work. I think the best option will be to se MapWhen like this:

app.MapWhen(httpContext => httpContext.GetMultiTenantContext<TenantInfo>()?.TenantInfo == null,
   adminApp =>
   {
     adminApp.UseSpa(spa =>
     {
       spa.Options.SourcePath = "angular/admin";
       spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
       {
           FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "angular", "admin"))
       };

       if (env.IsDevelopment())
         spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
      });
    });

app.MapWhen(httpContext => httpContext.GetMultiTenantContext<TenantInfo>()?.TenantInfo != null,
    userApp =>
    {
      userApp.UseSpa(spa =>
      {
        spa.Options.SourcePath = "angular/user";
        spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "angular", "user"))
        };

        if (env.IsDevelopment())
          spa.UseProxyToSpaDevelopmentServer("http://localhost:4201");
      });
  }); 

Good luck and let me now how it works out.

1reaction
AndrewTriesToCodecommented, Sep 17, 2021

Hm, hard for me to be much help with my lack of knowledge on the SPA stuff – do you have a projet on github I can fork to take a look at the issue closer?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi-Tenant Single-Page Apps: Dos and Don'ts
A multi-tenant web application is a single instance of an application that serves multiple customers. All the customers share the same database, ...
Read more >
Multi-tenant SPA with multiple OIDC providers
I'm building a multi-tenant app that has the unusual requirement of allowing tenants to use their own choice of external systems for login/ ......
Read more >
Help With Multi-Tenant SPA/REST Application
I want to create a SPA & REST API. The registration will be handled by the SPA. When a user signs up, both...
Read more >
Multi Tenancy on SPA
Multi Tenancy on SPA. Hello,. I have a project developed on Laravel + VUEJS. I use passport for authentication and i have authorization...
Read more >
creating a multitenant SPA backed by restful web services
I am trying to create a multi tenant SPA (Single Page App) using HTML5/Javascript. This app will invoke restful webservices for data updates ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found