Comments (4)
I think this is irrelevant. In both cases (subdomain vs url path) you'd need to write some plug that checks either subdomain or url path to get the tenant name on each request.
from apartmentex.
@shulhi this is all I did:
defmodule App.TenantController do
plug :set_current_tenant
defp set_current_tenant(conn, _params) do
{"host", host} = List.keyfind(conn.req_headers, "host", 0)
tenant = Tenant.get_by_host!(host)
assign(conn, :current_tenant, tenant)
end
end
defmodule App.Tenant do
def get_by_host!(host) do
subdomain = host
|> String.split(".")
|> Enum.take(1)
|> Enum.join(".")
Repo.get_by!(__MODULE__, subdomain: subdomain)
end
end
from apartmentex.
To add to the advice above, the tenant qualification can really come from anywhere- subdomain, path, jwt claim, some other header, etc. basically anything you can access in plug on a request can be used to target a schema
from apartmentex.
Thanks, I got it working with plug.
from apartmentex.
Related Issues (20)
- Having trouble with install HOT 4
- Support for UUIDs HOT 1
- function Mariaex.Error.message/1 is undefined HOT 2
- The one question - is this ready for production? HOT 2
- Prefix in `Apartmentex.drop_tenant` not being escaped properly? HOT 4
- ** (Postgrex.Error) ERROR (undefined_table): relation "locations" does not exist HOT 4
- Migrating existing tables to multi tenant HOT 1
- Dump a Sample Tenant Structure HOT 5
- Ecto 2.1 compatibility issues HOT 6
- Customise migration folder HOT 1
- How to use prefix for schema's name in the project HOT 2
- Feature: Flag a migration as tenant based. HOT 6
- pool size? HOT 2
- New Patch Release? HOT 2
- Foreign key issue HOT 3
- Broken deps as Ecto was upgraded HOT 4
- Unable to run tenant_migrations on production remote_console HOT 2
- Compilation fails: cannot import Mix.Ecto.build_repo_priv/1 HOT 4
- Move Migrations from Scripts to Compiled Code HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apartmentex.