needle-innovision / nestjs-tenancy

Multi-tenancy approach for nestjs - currently supported only for mongodb with mongoose
MIT License
187 stars 58 forks source link

Fix for missing tenantId from subdomain #7

Closed jarrilla closed 3 years ago

jarrilla commented 3 years ago

Fixes #6

NestJS doesn't seem to load host subdomains into Request.subdomains[] so existing logic for reading subdomains was ineffective.

Now using same logic of getting subdomains from Request.headers.host for both express and fastify.

sandeepsuvit commented 3 years ago

Hi @jarrilla Thanks for submitting the PR. Could you also specify if its a NestJs version update caused this issue. Since last time I checked, up until v7.0.0 we had to specifically use the Fastify adapter request to get the subdomain object. If that's the case then ill have to bump the dependency version up.

jarrilla commented 3 years ago

I apologize for the confusion.

I was unaware that the default subdomain offset in express is 2. Thus when pinging subdomain.localhost:3000 for request.subdomains I kept getting [], rather than the expected ['subdomain'].

(See here for more: https://stackoverflow.com/questions/29146489/how-to-get-local-subdomains-using-express-js-s-req-subdomains)

Inserting

app.set('subdomain offset', 1) solves this issue for testing.