@@ -5,10 +5,7 @@ import { outdent as javascript } from 'outdent'
5
5
6
6
import type { NextConfig } from '../helpers/config'
7
7
8
- import type { NextServerType } from './handlerUtils'
9
-
10
8
/* eslint-disable @typescript-eslint/no-var-requires */
11
-
12
9
const { promises } = require ( 'fs' )
13
10
const { Server } = require ( 'http' )
14
11
const path = require ( 'path' )
@@ -22,17 +19,17 @@ const {
22
19
getMaxAge,
23
20
getMultiValueHeaders,
24
21
getPrefetchResponse,
25
- getNextServer,
26
22
normalizePath,
27
23
} = require ( './handlerUtils' )
24
+ const { NetlifyNextServer } = require ( './server' )
28
25
/* eslint-enable @typescript-eslint/no-var-requires */
29
26
30
27
type Mutable < T > = {
31
28
- readonly [ K in keyof T ] : T [ K ]
32
29
}
33
30
34
31
// We return a function and then call `toString()` on it to serialise it as the launcher function
35
- // eslint-disable-next-line max-params
32
+ // eslint-disable-next-line max-params, max-lines-per-function
36
33
const makeHandler = ( conf : NextConfig , app , pageRoot , staticManifest : Array < [ string , string ] > = [ ] , mode = 'ssr' ) => {
37
34
// Change working directory into the site root, unless using Nx, which moves the
38
35
// dist directory and handles this itself
@@ -68,22 +65,30 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str
68
65
// We memoize this because it can be shared between requests, but don't instantiate it until
69
66
// the first request because we need the host and port.
70
67
let bridge : NodeBridge
71
- const getBridge = ( event : HandlerEvent ) : NodeBridge => {
68
+ const getBridge = ( event : HandlerEvent , context : HandlerContext ) : NodeBridge => {
69
+ const {
70
+ clientContext : { custom : customContext } ,
71
+ } = context
72
+
72
73
if ( bridge ) {
73
74
return bridge
74
75
}
75
76
const url = new URL ( event . rawUrl )
76
77
const port = Number . parseInt ( url . port ) || 80
77
78
base = url . origin
78
79
79
- const NextServer : NextServerType = getNextServer ( )
80
- const nextServer = new NextServer ( {
81
- conf,
82
- dir,
83
- customServer : false ,
84
- hostname : url . hostname ,
85
- port,
86
- } )
80
+ const nextServer = new NetlifyNextServer (
81
+ {
82
+ conf,
83
+ dir,
84
+ customServer : false ,
85
+ hostname : url . hostname ,
86
+ port,
87
+ } ,
88
+ {
89
+ revalidateToken : customContext . odb_refresh_hooks ,
90
+ } ,
91
+ )
87
92
const requestHandler = nextServer . getRequestHandler ( )
88
93
const server = new Server ( async ( req , res ) => {
89
94
try {
@@ -119,7 +124,7 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str
119
124
process . env . _NETLIFY_GRAPH_TOKEN = graphToken
120
125
}
121
126
122
- const { headers, ...result } = await getBridge ( event ) . launcher ( event , context )
127
+ const { headers, ...result } = await getBridge ( event , context ) . launcher ( event , context )
123
128
124
129
// Convert all headers to multiValueHeaders
125
130
@@ -180,6 +185,7 @@ export const getHandler = ({ isODB = false, publishDir = '../../../.next', appDi
180
185
// We copy the file here rather than requiring from the node module
181
186
const { Bridge } = require ( "./bridge" ) ;
182
187
const { augmentFsModule, getMaxAge, getMultiValueHeaders, getPrefetchResponse, getNextServer, normalizePath } = require ( './handlerUtils' )
188
+ const { NetlifyNextServer } = require ( './server' )
183
189
184
190
${ isODB ? `const { builder } = require("@netlify/functions")` : '' }
185
191
const { config } = require ( "${ publishDir } /required-server-files.json" )
0 commit comments