generated from DTS-STN/next-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #915 from DTS-STN/999999-HotFix-BlockApi
999999 - Block api calls in production
- Loading branch information
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NextResponse } from 'next/server' | ||
import type { NextRequest } from 'next/server' | ||
|
||
// This function can be marked `async` if using `await` inside | ||
export function middleware(request: NextRequest) { | ||
// | ||
const AuthRequired = | ||
process.env.APP_ENV === 'production' || process.env.APP_ENV === 'alpha' | ||
|
||
const url = request.nextUrl | ||
const { pathname } = url | ||
|
||
if (AuthRequired) { | ||
if (pathname.startsWith(`/api/`)) { | ||
if ( | ||
!request.headers | ||
.get('referer') | ||
?.includes('estimateursv-oasestimator.service.canada.ca') | ||
) { | ||
return NextResponse.redirect(new URL('/', request.url)) | ||
} | ||
} | ||
} | ||
|
||
return NextResponse.next() | ||
} | ||
|
||
// See "Matching Paths" below to learn more | ||
export const config = { | ||
matcher: ['/((?!_next|fonts|examples|svg|[\\w-]+\\.\\w+).*)'], | ||
} |