Websites v4 docs v5.2.4
    Preparing search index...

    Middleware & Routing

    Requests are routed via middleware (in middleware.ts).

    The getDomain() function runs to get the domain/hostname (e.g. stags.agent.v4.homeflow.co.uk or www.ramptonbaseley.com).

    Once we have the domain, the middleware rewrites the request to /${hostname}/${path}. For example, a request to rampton-baseley.agent.v4.homeflow.co.uk/branches will be rewritten to /rampton-baseley.agent.v4.homeflow.co.uk/branches, and render the page file app/[domain]/branches/page.tsx, with domain passed to the page as part of the params prop.

    Admin routes must be authenticated, so for requests to admin (e.g. stags.admin.v4.homeflow.co.uk) the middleware will first check for a session cookie and verify the session. It will redirect to /auth/signin if that verification is unsuccessful, where the user will be prompted to log in.

    There is a fairly long list of rewrites for different routes in the next.config.js file. Each of these is prefixed with ROUTE_PREFIX (the string '/:domain/:theme') to ensure it includes the domain and theme params when it is rewritten.

    Note that many of the rewrites convert URL params like /sales to a query param, e.g. ?channel=sales, so this is how it is received as a prop in the page component.

    {
    source: `${ROUTE_PREFIX}/:postcode([A-Za-z]{1,2}\\d[A-Za-z\\d]?\\s*-\\d[A-Za-z]{2})/:channel(sales|lettings)/:fragment*`,
    destination: `${ROUTE_PREFIX}/properties?postcode=:postcode&channel=:channel&fragment=:fragment*`,
    },