@@ -3,7 +3,6 @@ import { getCallId, NAV_CALL_ID_TAG } from "@/app/stillinger/_common/monitoring/
3
3
import { getSessionId , SESSION_ID_TAG } from "@/app/stillinger/_common/monitoring/session" ;
4
4
import { CURRENT_VERSION , migrateSearchParams } from "@/app/stillinger/(sok)/_utils/versioning/searchParamsVersioning" ;
5
5
import { QueryNames } from "@/app/stillinger/(sok)/_utils/QueryNames" ;
6
- import { CookieBannerUtils } from "@navikt/arbeidsplassen-react" ;
7
6
8
7
/*
9
8
* Match all request paths except for the ones starting with:
@@ -13,18 +12,11 @@ import { CookieBannerUtils } from "@navikt/arbeidsplassen-react";
13
12
* Source: https://nextjs.org/docs/pages/building-your-application/configuring/content-security-policy
14
13
*/
15
14
const CSP_HEADER_MATCH = / ^ \/ ( (? ! a p i | _ n e x t \/ s t a t i c | f a v i c o n .i c o ) .* ) $ / ;
16
- const FAST_API_HEADER_MATCH = / ^ \/ ( (? ! .* a p i .* | _ n e x t \/ s t a t i c | f a v i c o n .i c o ) .* ) $ / ;
17
- const FAST_API_APP_ID_PROD = "41fb84fd-4ff3-43f4-b7e0-d84444fb2f91" ;
18
- const FAST_API_APP_ID_DEV = "501ec40e-4010-4cb4-ad13-61ab529dd765" ;
19
15
20
16
function shouldAddCspHeaders ( request : NextRequest ) {
21
17
return new RegExp ( CSP_HEADER_MATCH ) . exec ( request . nextUrl . pathname ) ;
22
18
}
23
19
24
- function shouldLogToFastApi ( request : NextRequest ) {
25
- return new RegExp ( FAST_API_HEADER_MATCH ) . exec ( request . nextUrl . pathname ) ;
26
- }
27
-
28
20
function addCspHeaders ( requestHeaders : Headers , responseHeaders : Headers ) {
29
21
const nonce = Buffer . from ( crypto . randomUUID ( ) ) . toString ( "base64" ) ;
30
22
const cspHeader = `
@@ -43,7 +35,7 @@ function addCspHeaders(requestHeaders: Headers, responseHeaders: Headers) {
43
35
frame-src 'self';
44
36
block-all-mixed-content;
45
37
${ process . env . NODE_ENV === "production" ? "upgrade-insecure-requests;" : "" } ;
46
- connect-src 'self' https://sentry.gc.nav.no umami.nav.no;
38
+ connect-src 'self' https://sentry.gc.nav.no umami.nav.no https://fastapi.nav.no ;
47
39
` ;
48
40
49
41
// Replace newline characters and spaces
@@ -63,47 +55,6 @@ function addSessionIdHeader(requestHeaders: Headers) {
63
55
requestHeaders . set ( SESSION_ID_TAG , getSessionId ( ) ) ;
64
56
}
65
57
66
- function logCookieValueToFastApi ( request : NextRequest ) {
67
- const pathname = request . nextUrl . pathname ;
68
- const appId = process . env . NODE_ENV === "production" ? FAST_API_APP_ID_PROD : FAST_API_APP_ID_DEV ;
69
-
70
- if ( ! / \. [ a - z A - Z 0 - 9 ] + $ / . test ( pathname ) ) {
71
- try {
72
- const userActionTaken = CookieBannerUtils . getUserActionTakenValue ( request . cookies ?. toString ( ) ) ;
73
- const hasCookieConsent = CookieBannerUtils . getConsentValues ( request . cookies ?. toString ( ) ) ;
74
- let eventName = "" ;
75
-
76
- if ( ! userActionTaken ) {
77
- eventName = "no-action" ;
78
- } else {
79
- if ( hasCookieConsent . analyticsConsent ) {
80
- eventName = "accepted" ;
81
- } else {
82
- eventName = "not-accepted" ;
83
- }
84
- }
85
-
86
- // Fire & Forget API Call (Non-blocking) + Log Response
87
- fetch ( "https://fastapi.nav.no/api/send" , {
88
- method : "POST" ,
89
- headers : { "Content-Type" : "application/json" } ,
90
- body : JSON . stringify ( {
91
- app_id : appId ,
92
- url_host : request . nextUrl . host ,
93
- url_path : pathname ,
94
- url_query : request . nextUrl . search ,
95
- event_name : eventName ,
96
- } ) ,
97
- } )
98
- . then ( ( response ) => response . text ( ) )
99
- . then ( ( data ) => console . log ( "Event sent successfully to Fast API:" , data ) )
100
- . catch ( ( err ) => console . error ( "Failed to send event to Fast API:" , err ) ) ;
101
- } catch ( err ) {
102
- console . error ( "An error occured sending event to Fast API:" , err ) ;
103
- }
104
- }
105
- }
106
-
107
58
const PUBLIC_FILE = / \. ( .* ) $ / ;
108
59
109
60
// Due to limitations in the edge runtime, we can't use the prom-client library to track metrics directly here.
@@ -134,10 +85,6 @@ export function middleware(request: NextRequest) {
134
85
addCspHeaders ( requestHeaders , responseHeaders ) ;
135
86
}
136
87
137
- if ( shouldLogToFastApi ( request ) ) {
138
- logCookieValueToFastApi ( request ) ;
139
- }
140
-
141
88
addCallIdHeader ( requestHeaders ) ;
142
89
addSessionIdHeader ( requestHeaders ) ;
143
90
0 commit comments