Skip to content

Commit

Permalink
blocking api calls in production
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGoC committed Oct 4, 2023
1 parent 8e3413e commit 09cb2bf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions DockerfileTest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# docker build --file DockerfileTest .
#
FROM node:16.15.1-alpine AS production
ENV NODE_ENV=production

# test = test uses legalValuesJson_test.json to run the all the tests
ENV NODE_ENV=test

SHELL ["/bin/sh", "-c"]

Expand Down Expand Up @@ -41,4 +43,5 @@ WORKDIR $home
COPY --chown=55:$group . .

RUN yarn install --immutable
RUN yarn run test:unit gisCoupleOnePenBenefit
#RUN yarn run test:unit gisCoupleOnePenBenefit
RUN yarn run test:unit
31 changes: 31 additions & 0 deletions pages/_middleware.tsx
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+).*)'],
}

0 comments on commit 09cb2bf

Please sign in to comment.