This project demonstrates a simple approach to creating a multitenant application using SvelteKit, leveraging the reroute
hook for request routing.
The app uses hostname-based routing to direct requests to tenant-specific routes, with a shared layout and custom server-side logic.
src/
├── ...
├── hooks.ts # Contains reroute logic
├── routes/
│ ├── +layout.svelte # Shared layout for all routes
│ ├── brand-one/ # Brand one routes
│ │ ├── +page.svelte
│ │ ├── about-us/
│ │ │ └── +page.svelte
│ │ └── blog/
│ │ └── +page.svelte
│ └── brand-two/ # Brand two routes
│ ├── +page.svelte
│ ├── about-us/
│ │ └── +page.svelte
│ └── blog/
│ └── +page.svelte
└──
reroute
hook examines the hostname.This approach allows you to serve multiple "brands" or tenants from a single SvelteKit application, with minimal code duplication and easy management of shared components and layouts.
npm install
npm run dev
http://localhost:5173
and http://127.0.0.1:5173
to see different tenantsTo add more tenants or modify routing logic, update the reroute
function in src/hooks.ts
and create corresponding route folders in the src/routes
directory.