krabs
krabs copied to clipboard
'Common pages' functionality
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.
If you use https://github.com/ds300/patch-package you can just use this patch I created https://gist.github.com/cj/a9c967c517c37aad09e41aa2e9779c25
Hi @cj, thank you again for showing how to solve this problem! Would you mind opening a PR for this? 🙂
Is this thread active?