-
Notifications
You must be signed in to change notification settings - Fork 15
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 #1765 from Plant-for-the-Planet-org/feature/my_forest
Feature/my forest
- Loading branch information
Showing
279 changed files
with
13,300 additions
and
5,774 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
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.