Skip to content

KwekuMoses/website-creator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

242 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.

This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

Next.js Multi-Tenant Middleware

This middleware enables multi-tenant functionality in a Next.js application, handling routing for subdomains and custom domains, authentication, and tenant-specific content delivery.

Features

Multi-tenant routing: Automatically routes requests to tenant-specific content based on subdomain or custom domain Authentication management: Protects routes with authentication and handles user sessions Custom domain support: Maps verified custom domains to their respective tenants Search engine control: Optional blocking of search engine bots based on configuration Path rewriting: Dynamically rewrites URLs to serve tenant-specific content Configuration

The middleware uses the following environment variables:

NEXT_PUBLIC_PROD_DOMAIN: Production domain (default: "bitbloom.se") NEXT_PUBLIC_LOCAL_DOMAIN: Local development domain (default: "localhost:3000") NEXT_PUBLIC_ALLOW_INDEXING: Set to 'false' to block search engine crawlers How It Works Request processing: Intercepts all incoming requests to the application Authentication check: Verifies user sessions for protected routes Domain resolution: Identifies the tenant based on subdomain or custom domain Path rewriting: Rewrites the request path to the tenant-specific content Public Paths

The following paths are accessible without authentication:

/login, /signup, /register, /auth/callback /_next/static /api/auth, /api/domains, /api/domains/verify Usage The middleware is automatically applied to all routes in your Next.js application. Key exported functions include:

middleware(req): Main middleware function that handles all requests addTenant(subdomain, tenantId): Helper function that returns appropriate host for a new tenant Database Integration The middleware interacts with a Supabase database to:

Fetch tenant configurations

Verify custom domains Manage authentication sessions Example When a user visits customername.bitbloom.se, the middleware:

Extracts the subdomain (customername) Looks up the tenant in the database Rewrites the request to /tenant/customername/... Similarly for verified custom domains like example.com, it maps to the appropriate tenant configuration.

Logging

The middleware includes detailed console logging for debugging purposes, tracking:

Environment and domain information Session status Subdomain extraction Custom domain verification Path rewriting For more information, see the middleware.ts file.

Releases

Packages

Contributors

Languages