Skip to content

Commit

Permalink
Merge pull request #2044 from Plant-for-the-Planet-org/hotfix/sync-de…
Browse files Browse the repository at this point in the history
…velop

Syncs develop with base branch for project redesign
  • Loading branch information
mohitb35 authored Apr 11, 2024
2 parents b070f9f + 1045a21 commit 4895e73
Show file tree
Hide file tree
Showing 348 changed files with 17,433 additions and 7,228 deletions.
6 changes: 5 additions & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ 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=
6 changes: 4 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import materialTheme from '../src/theme/themeStyles';
import { ThemeProvider } from '@storybook/theming';
import { I18nextProvider } from 'react-i18next';
import i18n from './i18n';
import { useEffect } from 'react';
import globalStyles from '../src/theme/theme';
import { lazy, useEffect } from 'react';
import { useTheme } from '../src/theme/themeContext';

// import { ThemeProvider } from 'emotion-theming';
Expand All @@ -16,6 +15,9 @@ import { useTheme } from '../src/theme/themeContext';
* Read more about them at:
* https://storybook.js.org/docs/react/writing-stories/decorators#global-decorators
*/

const globalStyles = lazy(() => import('../src/theme/theme'));

export const decorators = [
(Story, context) => {
const { locale } = context.globals;
Expand Down
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 4895e73

Please sign in to comment.