Replies: 2 comments
|
The article is pretty great. As far as I know, there's nothing built-in but yeah SSR allows you to do anything. I think domain multi-tenants is often something to tackle on the host site. Sorry I can't provide a better answer but maybe someone else has an idea! |
|
Yes. With on-demand rendering (an adapter + 1. Resolve the tenant from the host in middleware // src/middleware.ts
import { defineMiddleware } from 'astro:middleware';
import { getTenantByHost } from './lib/tenants'; // your DB / KV lookup
export const onRequest = defineMiddleware(async (context, next) => {
const tenant = await getTenantByHost(context.url.hostname);
if (!tenant) return new Response('Unknown site', { status: 404 });
context.locals.tenant = tenant;
return next();
});Pages then read The gotcha: // astro.config.mjs
export default defineConfig({
output: 'server',
security: {
allowedDomains: [
{ hostname: '**.yourplatform.com', protocol: 'https' },
// For arbitrary customer domains, [{}] trusts any host.
// Only do that behind a proxy you control, and still reject
// unknown hosts in middleware like above.
],
},
});2. Point arbitrary domains at the deployment (this is the host's job) Astro doesn't handle it; it's DNS + TLS on your platform, and it's the part the article can't cover for arbitrary domains:
Your onboarding flow then becomes: customer adds a CNAME → you register the hostname with the host API → you store One last thing: pages that differ per tenant can't be prerendered at build time, since the build doesn't know the host. Keep those on-demand, and if you cache them at the CDN, make sure the cache key includes the host. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Is there a way to make an Astro app that can handle multiple domains? Or is Astro single-domain only?
EDIT: I guess I found an answer, but I don’t see any official documentation for this. Plus I’m looking to handle arbitrary domains.
All reactions