Skip to content

Commit

Permalink
Update matcher path
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreyaschorge committed Dec 10, 2023
1 parent a868062 commit c9287b1
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 13 deletions.
32 changes: 32 additions & 0 deletions folderCrawler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fs = require('fs');
const path = require('path');

function crawlFolderStructure(rootDir) {
const files = [];
function crawlDirectory(dir) {
const items = fs.readdirSync(dir);

for (const item of items) {
const itemPath = path.join(dir, item);
const stats = fs.statSync(itemPath);

if (stats.isDirectory()) {
crawlDirectory(itemPath); // Recursive call for subdirectories
} else {
files.push(`/${path.relative(rootDir, itemPath).replace(/\[.*?\]/g, ':path').replace(/\/?index\.tsx?$/, '').replace(/\.tsx?$/, '')}`); // Add modified file path to the array
}
}
}
try {
crawlDirectory(rootDir);
return files;
} catch (error) {
console.error('Error while crawling:', error.message);
return [];
}
}

const scriptDir = __dirname;
const rootPath = path.join(scriptDir, 'pages');
const fileList = crawlFolderStructure(rootPath);
console.log(fileList);
83 changes: 71 additions & 12 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,82 @@
import { NextRequest, NextResponse } from 'next/server';
import { getTenantSlug } from './src/utils/multiTenancy/helpers';

// export const config = {
// matcher: ['/_sites/:slug/*'],
// };

export const config = {
matcher: [
/*
* Match all paths except for:
* 1. /api routes
* 2. /_next (Next.js internals)
* 3. /_static (inside /public)
* 4. all root files inside /public (e.g. /favicon.ico)
*/
'/((?!api/|_next/|_static/|_vercel|[\\w-]+\\.\\w+).*)',
'/404',
'/:path',
'/_app',
'/_document',
'/_error.js',
'/_sites/:path/:path',
'/_sites/:path/all',
'/_sites/:path/claim/:path/:path',
'/_sites/:path/complete-signup',
'/_sites/:path/home',
'/_sites/:path',
'/_sites/:path/login',
'/_sites/:path/verify-email',
'/all',
'/api/data-explorer/export',
'/api/data-explorer/species-planted',
'/api/data-explorer/total-species-planted',
'/api/data-explorer/total-trees-planted',
'/api/data-explorer/trees-planted',
'/api/trpc/:path',
'/claim/:path/:path',
'/complete-signup',
'/home',
'/',
'/login',
'/profile/api-key',
'/profile/bulk-codes/:path/:path',
'/profile/bulk-codes/:path',
'/profile/bulk-codes',
'/profile/delete-account',
'/profile/donation-link',
'/profile/edit',
'/profile/forest',
'/profile/giftfund',
'/profile/history',
'/profile/impersonate-user',
'/profile',
'/profile/payouts/add-bank-details',
'/profile/payouts/edit-bank-details/:path',
'/profile/payouts',
'/profile/payouts/schedule',
'/profile/planetcash',
'/profile/planetcash/new',
'/profile/planetcash/transactions',
'/profile/projects/:path',
'/profile/projects',
'/profile/projects/new-project',
'/profile/recurrency',
'/profile/redeem/:path',
'/profile/register-trees',
'/profile/treemapper/data-explorer',
'/profile/treemapper/import',
'/profile/treemapper',
'/profile/treemapper/my-species',
'/profile/widgets',
'/s/:path',
'/t/:path',
'/verify-email',
],
};

// export const config = {
// matcher: [
// /*
// * Match all paths except for:
// * 1. /api routes
// * 2. /_next (Next.js internals)
// * 3. /_static (inside /public)
// * 4. all root files inside /public (e.g. /favicon.ico)
// */
// '/((?!api/|_next/|_static/|_vercel|[\\w-]+\\.\\w+).*)',
// ],
// };

export default async function middleware(req: NextRequest) {
const url = req.nextUrl;

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
"./src/**/*",
"tenant.config.ts",
"public/assets"
]
, "folderCrawler.js" ]
}

0 comments on commit c9287b1

Please sign in to comment.