-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2044 from Plant-for-the-Planet-org/hotfix/sync-de…
…velop Syncs develop with base branch for project redesign
- Loading branch information
Showing
348 changed files
with
17,433 additions
and
7,228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { getTenantSlug } from './src/utils/multiTenancy/helpers'; | ||
|
||
export const config = { | ||
matcher: [ | ||
// This regular expression matches any string except those containing "api", "static", files with extensions, or "_next". | ||
'/((?!api|static|.*\\..*|_next).*)', | ||
'/', | ||
'/sites/:slug*', | ||
], | ||
}; | ||
|
||
export default async function middleware(req: NextRequest) { | ||
const url = req.nextUrl; | ||
|
||
const host = req.headers.get('host'); | ||
|
||
const slug = await getTenantSlug(host!); | ||
|
||
// Prevent security issues – users should not be able to canonically access | ||
// the pages/sites folder and its respective contents. | ||
if (url.pathname.startsWith(`/sites`)) { | ||
url.pathname = `/404`; | ||
} else { | ||
// rewrite to the current subdomain under the pages/sites folder | ||
url.pathname = `/sites/${slug}${url.pathname}`; | ||
} | ||
|
||
return NextResponse.rewrite(url); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.