Skip to content

Commit

Permalink
Merge pull request #1765 from Plant-for-the-Planet-org/feature/my_forest
Browse files Browse the repository at this point in the history
Feature/my forest
  • Loading branch information
mariahosfeld authored Feb 26, 2024
2 parents 57699e9 + a40ef14 commit 89066d5
Show file tree
Hide file tree
Showing 279 changed files with 13,300 additions and 5,774 deletions.
9 changes: 8 additions & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ NEXT_PUBLIC_DONATION_URL=https://donate.plant-for-the-planet.org
CONFIG_URL=https://app.plant-for-the-planet.org/app/config
VERCEL_URL=localhost

DB_CONN_URL=
DB_CONN_URL=

#Redis
REDIS_URL=
REDIS_TOKEN=
REDIS_HOST=
REDIS_PORT=
REDIS_PASSWORD=
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);
30 changes: 30 additions & 0 deletions middleware.ts
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);
}
4 changes: 3 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ const nextConfig = {
SITE_IMAGERY_API_URL: SITE_IMAGERY_API_URL,
WIDGET_URL: process.env.WIDGET_URL,
CONFIG_URL: process.env.CONFIG_URL,
ENABLE_ANALYTICS: DB_CONN_URL ? 'true' : 'false',
ENABLE_ANALYTICS: DB_CONN_URL ? true : false,
REDIS_URL: process.env.REDIS_URL,
REDIS_TOKEN: process.env.REDIS_TOKEN,
},
trailingSlash: false,
reactStrictMode: true,
Expand Down
Loading

0 comments on commit 89066d5

Please sign in to comment.