Skip to content

Commit

Permalink
Merge pull request #915 from DTS-STN/999999-HotFix-BlockApi
Browse files Browse the repository at this point in the history
999999 - Block api calls in production
  • Loading branch information
MarcoGoC authored Oct 5, 2023
2 parents db3d7d8 + 09cb2bf commit 44db77c
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 44db77c

Please sign in to comment.