Search code examples
node.jsexpresssubdomain

Use subdomain middleware to match client workspace


I'm building a platform using Node + Express stack that will be used by different companies. For presentation, I want to create subdomains with the name of each company to access my platform in a way that I can link all requests from that company to its data and not the data from all companies.

One easy example is Harvest, where each of their client have a single subdomain. For example, company A uses https://companyA.harvestapp.com/ while company B uses https://companyB.harvestapp.com/.

My first thought was to include a unique URL for each company on my database and create a middleware to check the company and pass it to each request.

Is it the best choice to make similar implementation using Node + Express?


Solution

  • Configuring & Managing subdomains per client could be overwhelming when the number of clients increases.

    My thoughts:

    1. Ask the user to enter the client id/name. Or, present a drop down for client selection.

    I won't prefer the client selection drop down, as this could expose your client names. I hope entering the client id is fine, again do not use client names.

    2. Manage Client & User information in a separate database.

    You can have a separate database, which keeps the list of Clients and users for each client. As part of login, you will fetch the Client ID for the logged in user from this database. When users are registered you should update this database also.

    Note: Never expose client details to end users / search engines.