Replies: 10 comments 29 replies
-
This would be a good example I think CC/ @kentcdodds |
Beta Was this translation helpful? Give feedback.
-
I would love to see an example on how to do this with remix 🥰 |
Beta Was this translation helpful? Give feedback.
-
I imagine it will be similar to examples with Next Js. e.g. https://vercel.com/guides/nextjs-multi-tenant-application. However I am interested in seeing how Remix might consume subdomain properties as well and how one might branch the render tree at the highest level possible to publish for different tenants. Forgive me in that I am setting up a test project this week to get my feet wet with Remix. I will post back my learnings as I get farther and find useful examples. |
Beta Was this translation helpful? Give feedback.
-
A friend of mine came up with a clever solution that works for me: You can simply extract the host information in your loader and return different data based on it:
No need for middleware, rewrites or complicated route structures :-) |
Beta Was this translation helpful? Give feedback.
-
@kiliman @sergioxda appreciate your responses. I have edited my comment to remove the $ in front of /subdomain, you are right, I can always get that from the header. But what I want is that when a request is made from a subdomain, I serve my routes from a directory called "subdomain" Instead of /routes/ which I would like to keep for the root domain only. Examples: Hope this clarifies. |
Beta Was this translation helpful? Give feedback.
-
Alright, this is possible in remix. You just need to use the express adapter, and make two production builds. Here's how you need to setup your server.js: let express = require("express");
const remix = require("@remix-run/express");
const app = express();
const isClientSite = (req) => {
if (
req.headers["host"] !== "localhost:3000" // your app domain here
)
return true;
return false;
};
app.use(express.static("public"));
app.use("/build", (req, res, next) => {
if (isClientSite(req)) {
express.static("public/build")(req, res, next);
} else {
express.static("public/build-main")(req, res, next);
}
});
app.all("*", (req, res, next) => {
if (isClientSite(req)) {
return remix.createRequestHandler({ build: require("./build") })(
req,
res,
next
);
}
return remix.createRequestHandler({ build: require("./build-main") })(
req,
res,
next
);
});
app.listen(process.env.PORT || 3000, () => console.log("server started!")); Then you will need to make two builds:
You need your app routes all inside I wrote more about it in a quick blog post: https://www.zerotofullstack.io/p/multi-tenancy-in-remix |
Beta Was this translation helpful? Give feedback.
-
Is there an easy and elegant way to do this: Point user.remix.com/settings to app/user/sertings.tsx point admin.remix.com to app/admin/settings.tsx? i do not want 1 single settings.tsx and do conditional logic on subdomain param. I want to link / route them to seperate route files. In rails you can do:
and
You can namespace the controllers ( remix route files) anyway you like. And you get routes with a link to route url admin.remix.com/games/ and app.remix.com/games. just easy and elegantly. This is a really big roadblock i hooe there is an elegant solution for this. having 1 settings.tsx route filled with conditin logic based on subdomain is not cutting it for me since then you have to go all the wat back to parent routes ( say different layouts per entity ) its just so not elegant and bloating the routes file. hope my usecas lllustrates it in clear what i like to achieve. |
Beta Was this translation helpful? Give feedback.
-
Honestly just use an nginx server pointing to multiple remix servers. I don't understand why any of this has to happen in remix?
? What's the down side of this approach ? |
Beta Was this translation helpful? Give feedback.
-
Unsure if it has been asked, but what if I want to have a universal login/signup page, but everything else to be under a subdomain? Can I redirect/rewrite the URL after the login/signup? |
Beta Was this translation helpful? Give feedback.
-
it 2024 and still no stress-free solution to this 🙁 |
Beta Was this translation helpful? Give feedback.
-
What is the new or updated feature that you are suggesting?
How to config Multi tenancy app on Remix?
Why should this feature be included?
Multi tenancy app
Beta Was this translation helpful? Give feedback.
All reactions