Skip to content
This repository was archived by the owner on Sep 25, 2023. It is now read-only.
This repository was archived by the owner on Sep 25, 2023. It is now read-only.

'Common pages' functionality #31

@TheLeePriest

Description

@TheLeePriest

Hi there!

I am currently working on a project that uses Next.js and I want to make use of Krabs for a multi-tenant approach. One thing I wanted to do was to have what I call 'common pages' between all the tenants. For example creating a resources page in the default Next.js pages directory would then allow that page to be used by all tenants.

I have a fork of the repo and believe that I have been able to achieve this by passing an extra options parameter in to the default krabs() function call. The options parameter is an object that currently contains a commonPages boolean, this could be extended going forward. The update to the utils/routes/resolve.ts file is as follows:

const fs = require('fs')
const path = require('path')

export function resolveRoutes(tenantName: string, pathname: string, commonPages: boolean | undefined): string {
  const pageExistsInTenant = fs.existsSync(path.join(process.cwd(), 'pages', tenantName, `${pathname}.js`));

  if(commonPages && !pageExistsInTenant && pathname !== '/') {
    return `${pathname}`
  }

  return pathname === '/' ? `/${tenantName}` : `/${tenantName}${pathname}`;
}

export default resolveRoutes;

As you can see the modification to the function is minor but offers that little bit more flexibility.

I would love to hear any and all of your feedback on what you think of potentially adding this functionality to Krabs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions