1

I have almost finished my first decoupled (frond and back ends are separate) project - the back end is written with django + rest framework and implements multitenancy (means my api endpoints look like tenant1.sitename.com/api/endpoint and tenant2.sitename.com/api/endpoint) . While I was developing, I assumed that there shouldn't be a problem consuming my api since the front end is the same for all tenants, so django could just consume same vue front end no matter which tenant.. ant then it struck me - actually it's vue consuming django api, not other way around.. and vue doesn't know which tenant is selected.. So now I'm very lost.

My main.ts looks like this

axios.defaults.baseURL = 'http://tenant1.mysite.local:8000/api/';
axios.defaults.withCredentials = true;

To reiterate: I have one back-end serving api for different tenants like t1.foo.com/api and t2.foo.com/api and one front-end that currently only sends requests to only one baseurl defined in settings, for example t1.foo.com/api ; It then serves it on t1.foo.com/home . Problem is, if I would to go to t2.foo.com/home , it would still send requests to t1.foo.com/api . I don't know neither how to make different (t1,t2,t3) urls accessible nor how to make it send requests to matching api. I want to acieve my frontent sending the api request to t1.foo.com/api when i go to to t1.foo.com/home and t2.foo.com/api when I go to t2.foo.com/home .

Edit: I have asked the separate question about how to achieve a suggested solution: how to use variables in base url and compose config when making the request in Vue.js?

illevens
  • 343
  • 1
  • 13
  • This seems opposite to what I would expect (I would expect each tenant to have different domains that use the same api). But if you want this I would say you could have a main backend url that you use for login that returns the user's tenant api url. – LLai Apr 17 '21 at 01:34
  • @LLai do you mean there is a need for a multitenency of Vue frontend as well ? How could I change which URL it serves files to depending on the API URL it accesses ? – illevens Apr 17 '21 at 05:57
  • It depends on your apps needs. Will you have customers that need their own domain/subdomain? – LLai Apr 17 '21 at 06:54
  • @LLai yes, and this is how backend api already works (there are t1.foo.com/api and t2.foo.com/api). I added better explanation to the question. – illevens Apr 17 '21 at 07:34
  • O if they are on the same domain then you could use something like `window.location.origin` on the frontend – LLai Apr 17 '21 at 08:22
  • do t1.site.com and t2.site.com count as same domain? – illevens Apr 18 '21 at 09:29
  • They are the same domain but are different subdomains – LLai Apr 18 '21 at 16:24
  • @illevens what did you end up doing ? Have the same question – ihor.eth Aug 29 '21 at 16:16
  • @ihorbond I couldn't really fix it – illevens Sep 08 '21 at 20:39
  • @illevens at first I ended up using relative url as baseUrl but then decided to determine tenant by origin or referrer header instead so all api calls are made without subdomain prefix. hope it helps – ihor.eth Sep 09 '21 at 01:44

0 Answers0