Skip to content

Commit

Permalink
add: feature flag middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
EnzoVieira committed Jan 26, 2024
1 parent 0bc92b6 commit c50dcdd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 54 deletions.
11 changes: 0 additions & 11 deletions context/FeatureFlags/FeatureFlag.js

This file was deleted.

24 changes: 0 additions & 24 deletions context/FeatureFlags/FeatureFlagsProvider.js

This file was deleted.

3 changes: 0 additions & 3 deletions context/FeatureFlags/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions context/FeatureFlags/useFeatureFlags.js

This file was deleted.

5 changes: 1 addition & 4 deletions layout/Home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { withoutAuth } from "@context/Auth";

import { Hero, Sponsors, Hackathon, Speakers, Partners } from "./components";
import { FeatureFlag } from "@context/FeatureFlags/FeatureFlag";

import Navbar from "@components/Navbar";
import Schedule from "@components/Schedule";
Expand All @@ -11,9 +10,7 @@ function Home() {
return (
<Navbar bgColor="secondary" button="quinary" fgColor="white">
{/* FIXME: The parameter could probably be better in some way */}
<FeatureFlag feature="BACKOFFICE">
<Hero />
</FeatureFlag>
<Hero />
<Schedule />
<Sponsors />
<Speakers />
Expand Down
20 changes: 20 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function middleware(request: NextRequest) {
if (!process.env.NEXT_PUBLIC_BACKOFFICE_FEATURE_FLAG) {
return NextResponse.redirect(new URL("/404", request.url));
}
}

export const config = {
matcher: [
"/attendee/:path*",
"/attendees/:path*",
"/badge/:path*",
"/product/:path*",
"/register/:path*",
"/sponsor/:path*",
"/staff/:path*",
],
};
12 changes: 4 additions & 8 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { AuthProvider } from "@context/Auth";
import Header from "@components/Header";

import { FeatureFlagsProvider } from "@context/FeatureFlags/FeatureFlagsProvider";

import "../styles/globals.css";

function App({ Component, pageProps }) {
return (
<FeatureFlagsProvider>
<AuthProvider>
<Header />
<Component {...pageProps} />
</AuthProvider>
</FeatureFlagsProvider>
<AuthProvider>
<Header />
<Component {...pageProps} />
</AuthProvider>
);
}

Expand Down

0 comments on commit c50dcdd

Please sign in to comment.