Finbuckle.MultiTenant icon indicating copy to clipboard operation
Finbuckle.MultiTenant copied to clipboard

Option to ignore specific routes and static files

Open DeeJayTC opened this issue 4 years ago • 7 comments

When working with a SPA approach I have a few common endpoints used for everyone and per tenant endpoints using route strategy.

Is there any way to ignore the tenant check for specific routes or all static files?

DeeJayTC avatar Feb 06 '20 20:02 DeeJayTC

Hi @DeeJayTC

For files if you place UseStaticFiles before UseMultiTenant regular files should not be affected. However there currently isn't a built in way to prevent the multitenant middleware from running otherwise. You could create a custom MultiTenantStrategy to do that, but I think this is an excellent idea for a new feature.

AndrewTriesToCode avatar Feb 06 '20 23:02 AndrewTriesToCode

Yea, especially when you use the dpa middleware its constantly looking up tenant from the hot module replacement checks , websocket connections etc, too.

Could you maybe, to make it easier add something that allows to say:

UseRouteStrategyExplicit( RoutesThatShouldCheckTenant )

Any other route is ignored?

Or else any route without the __ Tenant __ is ignored automatically per option?

DeeJayTC avatar Feb 06 '20 23:02 DeeJayTC

SPA middleware...not dpa :)

DeeJayTC avatar Feb 06 '20 23:02 DeeJayTC

In a similar place here with a SPA application and it looks very chatty on the server end checking finbuckle tenancy unnecessarily. Will try and implement a custom strategy but will also greatly welcome the proposed enhancement.

hbermani avatar Feb 20 '20 11:02 hbermani

Thanks for the input!

It's funny because in ASP.NET Core 2.1 you actually can set a different route for the strategy but then in ASP.NET Core 2.2 they changed to "Endpoint" routing which overall is better but has this one issue.

In general the tenant strategy is fast but the tenant store check can be slow. So with that in mind I have a few ideas. Tell me what you think:

  1. Exception list - Have a way to tell the middleware to ignore certain identifiers if it finds them. E.g. if it thinks it finds a tenant identifier of 'spa_folder' then just treat it like a null and don't look into the store, etc.
  2. Add events to the middleware like with authentication so you can register a function for events like OnTenantIdentifierFound, check the identifier it found, and tell it to ignore it by setting a result to Handled or something like that.

I plan to do both, hopefully #1 in the next release.

AndrewTriesToCode avatar Feb 20 '20 19:02 AndrewTriesToCode

Thanks for the input!

It's funny because in ASP.NET Core 2.1 you actually can set a different route for the strategy but then in ASP.NET Core 2.2 they changed to "Endpoint" routing which overall is better but has this one issue.

In general the tenant strategy is fast but the tenant store check can be slow. So with that in mind I have a few ideas. Tell me what you think:

  1. Exception list - Have a way to tell the middleware to ignore certain identifiers if it finds them. E.g. if it thinks it finds a tenant identifier of 'spa_folder' then just treat it like a null and don't look into the store, etc.
  2. Add events to the middleware like with authentication so you can register a function for events like OnTenantIdentifierFound, check the identifier it found, and tell it to ignore it by setting a result to Handled or something like that.

I plan to do both, hopefully #1 in the next release.

In my case Finbuckle middleware is running even when the React app is being loaded. I think that's partly due to poor architecture my end. I was thinking I will separate the SPA to load from a different project where multitenancy is not required and then just run the backend APIs and persistence with multitenancy.

Update: Implemented the above and it now works better.

hbermani avatar Feb 20 '20 20:02 hbermani

@hbermani Excellent!

AndrewTriesToCode avatar Feb 26 '20 02:02 AndrewTriesToCode