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

'Common pages' functionality #31

Open
TheLeePriest opened this issue Nov 8, 2021 · 3 comments
Open

'Common pages' functionality #31

TheLeePriest opened this issue Nov 8, 2021 · 3 comments

Comments

@TheLeePriest
Copy link

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.

@cj
Copy link

cj commented Nov 13, 2021

If you use https://github.com/ds300/patch-package you can just use this patch I created https://gist.github.com/cj/a9c967c517c37aad09e41aa2e9779c25

@micheleriva
Copy link
Owner

Hi @cj, thank you again for showing how to solve this problem! Would you mind opening a PR for this? 🙂

TheLeePriest added a commit to TheLeePriest/krabs that referenced this issue Nov 21, 2021
@mihir-karbelkar-wiz
Copy link

Is this thread active?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants