K
K
Kirill2021-08-02 16:59:48
Django
Kirill, 2021-08-02 16:59:48

How to implement SAAS with subdomains in Django?

Hello.

Guys, there is a task to implement a small SAAS (in the end it turned out that the task is very large) with the following goodies:

- Each client must have its own subdomain on our main domain, i.e. customer1.example.com, customer2.example.com - at the same time, these domains must be set by the customers themselves during registration. Perhaps someone knows a package for Django that allows you to implement this using the "One database - One schema" approach, i.e. in the table the tenant_id field is added it is admissible? Or maybe it's better to use the "One base - One customer" approach? (here, of course, the question arises of automating the creation of this database for the customer and is it advisable?) (and maybe someone has instructions on how to configure nginx so that clients can attach personal domains to their custom subdomains, i.e. for example, the client has personal domain cabinet.site.ru, he prescribes settings in his DNS so that requests from his cabinet.site.ru go to customer1.example.

- The service itself needs to be done as a SPA using Vue for the web face, Graphene for the back end, so that you can use GraphQL - and then the question is how to cross this whole thing so that Vue can understand on which domain the application is open and can give this information backend?

I understand that the question is very vague, at the moment, I don’t know how to formulate it more specifically, because For 2 days I have been googling the topic of how to organize multi tenancy on django and at the same time, to use Vue and Graphene. Therefore, I have already come here, I will be grateful for any links to materials (it would help a lot), thoughts, tips to somehow move forward and structure the information in my head.

Thank you all in advance for your replies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alternativshik, 2021-08-03
@alternativshik

You make a middleware on the back, which will take the domain to which you applied from the request, then you determine your customer by domain, authenticate, authorize and do whatever your heart desires - database routing, custom api-endpoints and generally everything.
Nginx is configured to handle all subdomains.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question