Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit ef5af9c

Browse files
authored
feat: archiving project redirect to user's github profile (#10386)
* feat: archiving project redirect to github profile * fix: tests are no longer required * fix: display home page * fix: remove header + footer
1 parent d88563f commit ef5af9c

File tree

3 files changed

+29
-125
lines changed

3 files changed

+29
-125
lines changed

.github/workflows/build.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,28 @@ jobs:
3434
- name: run ${{ matrix.step }}
3535
run: npm run ${{ matrix.step }}
3636

37-
tests:
38-
needs: build
39-
runs-on: ubuntu-latest
40-
services:
41-
mongo:
42-
image: mongo
43-
ports:
44-
- 27017:27017
45-
strategy:
46-
fail-fast: false
47-
matrix:
48-
shardIndex: [1, 2, 3, 4, 5]
49-
shardTotal: [5]
50-
steps:
51-
- uses: actions/checkout@v4
52-
- uses: actions/setup-node@v4
53-
with:
54-
node-version: "18"
55-
cache: "npm"
56-
- name: install dependencies
57-
run: npm ci
58-
- name: Install Playwright's dependencies
59-
run: npx playwright install chromium
60-
- name: run tests
61-
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
37+
# tests:
38+
# needs: build
39+
# runs-on: ubuntu-latest
40+
# services:
41+
# mongo:
42+
# image: mongo
43+
# ports:
44+
# - 27017:27017
45+
# strategy:
46+
# fail-fast: false
47+
# matrix:
48+
# shardIndex: [1, 2, 3, 4, 5]
49+
# shardTotal: [5]
50+
# steps:
51+
# - uses: actions/checkout@v4
52+
# - uses: actions/setup-node@v4
53+
# with:
54+
# node-version: "18"
55+
# cache: "npm"
56+
# - name: install dependencies
57+
# run: npm ci
58+
# - name: Install Playwright's dependencies
59+
# run: npx playwright install chromium
60+
# - name: run tests
61+
# run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}

components/layouts/MultiLayout.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Navbar from "@components/navbar/Navbar";
2-
import Footer from "@components/Footer";
31
import SkipLink from "@components/SkipLink";
42
import Alert from "./Alert";
53

@@ -11,13 +9,11 @@ export default function MultiLayout({ settings, children }) {
119
{(!settings || !settings.hideNavbar) && (
1210
<>
1311
<Alert />
14-
<Navbar />
1512
</>
1613
)}
1714
<main id="main" className="flex-1 dark:bg-dark-2 dark:z-40">
1815
{children}
1916
</main>
20-
{(!settings || !settings.hideFooter) && <Footer />}
2117
</div>
2218
</>
2319
);

middleware.js

Lines changed: 4 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,16 @@
1-
import { getToken } from "next-auth/jwt";
21
import { NextResponse } from "next/server";
32

43
// note: logger is not available in middleware, using console.log instead
54

65
export const config = {
7-
matcher: [
8-
"/",
9-
10-
// account management
11-
"/account/:path*",
12-
"/api/account/:path*",
13-
14-
// admin section
15-
"/admin/:path*",
16-
"/api/admin/:path*",
17-
],
6+
matcher: ["/:path*"],
187
};
198

209
export async function middleware(req) {
21-
const protocol = process.env.NODE_ENV === "development" ? "http" : "https";
22-
const hostname = req.headers.get("host");
23-
const reqPathName = req.nextUrl.pathname;
24-
const sessionRequired = ["/account", "/api/account"];
25-
const adminRequired = ["/admin", "/api/admin"];
26-
const adminUsers = process.env.ADMIN_USERS.split(",");
27-
const hostedDomain = process.env.NEXT_PUBLIC_BASE_URL.replace(
28-
/http:\/\/|https:\/\//,
29-
"",
30-
);
31-
const hostedDomains = [hostedDomain, `www.${hostedDomain}`];
32-
33-
// if custom domain + on root path
34-
if (!hostedDomains.includes(hostname) && reqPathName === "/") {
35-
console.log(`custom domain used: "${hostname}"`);
36-
37-
let res;
38-
let profile;
39-
let url = `${
40-
process.env.NEXT_PUBLIC_BASE_URL
41-
}/api/search/${encodeURIComponent(hostname)}`;
42-
try {
43-
res = await fetch(url, {
44-
method: "GET",
45-
headers: {
46-
"Content-Type": "application/json",
47-
},
48-
});
49-
profile = await res.json();
50-
} catch (e) {
51-
console.error(url, e);
52-
return NextResponse.error(e);
53-
}
54-
55-
if (
56-
profile?.username &&
57-
profile.settings?.domain &&
58-
profile.settings.domain === hostname
59-
) {
60-
console.log(
61-
`custom domain matched "${hostname}" for username "${profile.username}" (protocol: "${protocol}")`,
62-
);
63-
// if match found rewrite to custom domain and display profile page
64-
return NextResponse.rewrite(
65-
new URL(
66-
`/${profile.username}`,
67-
`${protocol}://${profile.settings.domain}`,
68-
),
69-
);
70-
}
71-
72-
console.error(`custom domain NOT matched "${hostname}"`);
73-
}
74-
75-
// if not in sessionRequired or adminRequired, skip
76-
if (
77-
!sessionRequired
78-
.concat(adminRequired)
79-
.some((path) => reqPathName.startsWith(path))
80-
) {
81-
return NextResponse.next();
82-
}
83-
84-
const session = await getToken({
85-
req: req,
86-
secret: process.env.NEXTAUTH_SECRET,
87-
});
88-
89-
// if no session reject request
90-
if (!session) {
91-
if (reqPathName.startsWith("/api")) {
92-
return NextResponse.json({}, { status: 401 });
93-
}
94-
return NextResponse.redirect(new URL("/auth/signin", req.url));
95-
}
10+
const path = req.nextUrl.pathname;
9611

97-
const username = session.username;
98-
// if admin request check user is allowed
99-
if (adminRequired.some((path) => reqPathName.startsWith(path))) {
100-
if (!adminUsers.includes(username)) {
101-
if (reqPathName.startsWith("/api")) {
102-
return NextResponse.json({}, { status: 401 });
103-
}
104-
return NextResponse.redirect(new URL("/404", req.url));
105-
}
12+
if (path !== "/") {
13+
return NextResponse.redirect(new URL(path, "https://github.com"));
10614
}
10715

10816
return NextResponse.next();

0 commit comments

Comments
 (0)