From c96a90692708d1f83006ca95d67048b8747746df Mon Sep 17 00:00:00 2001 From: Eddie Jaoude Date: Sun, 9 Jun 2024 09:12:56 +0100 Subject: [PATCH 1/4] feat: archiving project redirect to github profile --- middleware.js | 100 +------------------------------------------------- 1 file changed, 2 insertions(+), 98 deletions(-) diff --git a/middleware.js b/middleware.js index af04e66d588..f403f105802 100644 --- a/middleware.js +++ b/middleware.js @@ -1,109 +1,13 @@ -import { getToken } from "next-auth/jwt"; import { NextResponse } from "next/server"; // note: logger is not available in middleware, using console.log instead export const config = { - matcher: [ - "/", - - // account management - "/account/:path*", - "/api/account/:path*", - - // admin section - "/admin/:path*", - "/api/admin/:path*", - ], + matcher: ["/:path*"], }; export async function middleware(req) { - const protocol = process.env.NODE_ENV === "development" ? "http" : "https"; - const hostname = req.headers.get("host"); const reqPathName = req.nextUrl.pathname; - const sessionRequired = ["/account", "/api/account"]; - const adminRequired = ["/admin", "/api/admin"]; - const adminUsers = process.env.ADMIN_USERS.split(","); - const hostedDomain = process.env.NEXT_PUBLIC_BASE_URL.replace( - /http:\/\/|https:\/\//, - "", - ); - const hostedDomains = [hostedDomain, `www.${hostedDomain}`]; - - // if custom domain + on root path - if (!hostedDomains.includes(hostname) && reqPathName === "/") { - console.log(`custom domain used: "${hostname}"`); - - let res; - let profile; - let url = `${ - process.env.NEXT_PUBLIC_BASE_URL - }/api/search/${encodeURIComponent(hostname)}`; - try { - res = await fetch(url, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - }); - profile = await res.json(); - } catch (e) { - console.error(url, e); - return NextResponse.error(e); - } - - if ( - profile?.username && - profile.settings?.domain && - profile.settings.domain === hostname - ) { - console.log( - `custom domain matched "${hostname}" for username "${profile.username}" (protocol: "${protocol}")`, - ); - // if match found rewrite to custom domain and display profile page - return NextResponse.rewrite( - new URL( - `/${profile.username}`, - `${protocol}://${profile.settings.domain}`, - ), - ); - } - - console.error(`custom domain NOT matched "${hostname}"`); - } - - // if not in sessionRequired or adminRequired, skip - if ( - !sessionRequired - .concat(adminRequired) - .some((path) => reqPathName.startsWith(path)) - ) { - return NextResponse.next(); - } - - const session = await getToken({ - req: req, - secret: process.env.NEXTAUTH_SECRET, - }); - - // if no session reject request - if (!session) { - if (reqPathName.startsWith("/api")) { - return NextResponse.json({}, { status: 401 }); - } - return NextResponse.redirect(new URL("/auth/signin", req.url)); - } - - const username = session.username; - // if admin request check user is allowed - if (adminRequired.some((path) => reqPathName.startsWith(path))) { - if (!adminUsers.includes(username)) { - if (reqPathName.startsWith("/api")) { - return NextResponse.json({}, { status: 401 }); - } - return NextResponse.redirect(new URL("/404", req.url)); - } - } - return NextResponse.next(); + return NextResponse.redirect(new URL(reqPathName, "https://github.com")); } From be2117f047cbd37258097eddbd0c1f312d4b4894 Mon Sep 17 00:00:00 2001 From: Eddie Jaoude Date: Sun, 9 Jun 2024 09:16:56 +0100 Subject: [PATCH 2/4] fix: tests are no longer required --- .github/workflows/build.yml | 50 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a1860717415..8c623ba3df9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,28 +34,28 @@ jobs: - name: run ${{ matrix.step }} run: npm run ${{ matrix.step }} - tests: - needs: build - runs-on: ubuntu-latest - services: - mongo: - image: mongo - ports: - - 27017:27017 - strategy: - fail-fast: false - matrix: - shardIndex: [1, 2, 3, 4, 5] - shardTotal: [5] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: "18" - cache: "npm" - - name: install dependencies - run: npm ci - - name: Install Playwright's dependencies - run: npx playwright install chromium - - name: run tests - run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} + # tests: + # needs: build + # runs-on: ubuntu-latest + # services: + # mongo: + # image: mongo + # ports: + # - 27017:27017 + # strategy: + # fail-fast: false + # matrix: + # shardIndex: [1, 2, 3, 4, 5] + # shardTotal: [5] + # steps: + # - uses: actions/checkout@v4 + # - uses: actions/setup-node@v4 + # with: + # node-version: "18" + # cache: "npm" + # - name: install dependencies + # run: npm ci + # - name: Install Playwright's dependencies + # run: npx playwright install chromium + # - name: run tests + # run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} From b32f24c823de3089f29d4db2030267ca0a9bc44c Mon Sep 17 00:00:00 2001 From: Eddie Jaoude Date: Mon, 10 Jun 2024 14:38:10 +0100 Subject: [PATCH 3/4] fix: display home page --- middleware.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/middleware.js b/middleware.js index f403f105802..8c11e9c9186 100644 --- a/middleware.js +++ b/middleware.js @@ -7,7 +7,11 @@ export const config = { }; export async function middleware(req) { - const reqPathName = req.nextUrl.pathname; + const path = req.nextUrl.pathname; - return NextResponse.redirect(new URL(reqPathName, "https://github.com")); + if (path !== "/") { + return NextResponse.redirect(new URL(path, "https://github.com")); + } + + return NextResponse.next(); } From 62494c0cf1d13357c8e4a5a0824d2c9b7cc48d12 Mon Sep 17 00:00:00 2001 From: Eddie Jaoude Date: Mon, 10 Jun 2024 15:01:06 +0100 Subject: [PATCH 4/4] fix: remove header + footer --- components/layouts/MultiLayout.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/layouts/MultiLayout.js b/components/layouts/MultiLayout.js index bbc9ebba071..aa0bc125fa6 100644 --- a/components/layouts/MultiLayout.js +++ b/components/layouts/MultiLayout.js @@ -1,5 +1,3 @@ -import Navbar from "@components/navbar/Navbar"; -import Footer from "@components/Footer"; import SkipLink from "@components/SkipLink"; import Alert from "./Alert"; @@ -11,13 +9,11 @@ export default function MultiLayout({ settings, children }) { {(!settings || !settings.hideNavbar) && ( <> - )}
{children}
- {(!settings || !settings.hideFooter) &&