@@ -33,6 +33,7 @@ import { NETLIFYDEVLOG, NETLIFYDEVWARN } from './command-helpers.mjs'
3333import createStreamPromise from './create-stream-promise.mjs'
3434import { headersForPath , parseHeaders } from './headers.mjs'
3535import { createRewriter , onChanges } from './rules-proxy.mjs'
36+ import { signRedirect } from './sign-redirect.mjs'
3637
3738const decompress = util . promisify ( zlib . gunzip )
3839const shouldGenerateETag = Symbol ( 'Internal: response should generate ETag' )
@@ -143,7 +144,7 @@ const alternativePathsFor = function (url) {
143144 return paths
144145}
145146
146- const serveRedirect = async function ( { match, options, proxy, req, res } ) {
147+ const serveRedirect = async function ( { match, options, proxy, req, res, siteInfo } ) {
147148 if ( ! match ) return proxy . web ( req , res , options )
148149
149150 options = options || req . proxyOptions || { }
@@ -155,6 +156,15 @@ const serveRedirect = async function ({ match, options, proxy, req, res }) {
155156 } )
156157 }
157158
159+ if ( match . signingSecret ) {
160+ req . headers [ 'x-nf-sign' ] = signRedirect ( {
161+ deployContext : 'dev' ,
162+ secret : match . signingSecret ,
163+ siteID : siteInfo . id ,
164+ siteURL : siteInfo . url ,
165+ } )
166+ }
167+
158168 if ( isFunction ( options . functionsPort , req . url ) ) {
159169 return proxy . web ( req , res , { target : options . functionsServer } )
160170 }
@@ -306,7 +316,7 @@ const reqToURL = function (req, pathname) {
306316
307317const MILLISEC_TO_SEC = 1e3
308318
309- const initializeProxy = async function ( { configPath, distDir, host, port, projectDir } ) {
319+ const initializeProxy = async function ( { configPath, distDir, host, port, projectDir, siteInfo } ) {
310320 const proxy = httpProxy . createProxyServer ( {
311321 selfHandleResponse : true ,
312322 target : {
@@ -370,13 +380,20 @@ const initializeProxy = async function ({ configPath, distDir, host, port, proje
370380 return proxy . web ( req , res , req . proxyOptions )
371381 }
372382 if ( req . proxyOptions && req . proxyOptions . match ) {
373- return serveRedirect ( { req, res, proxy : handlers , match : req . proxyOptions . match , options : req . proxyOptions } )
383+ return serveRedirect ( {
384+ req,
385+ res,
386+ proxy : handlers ,
387+ match : req . proxyOptions . match ,
388+ options : req . proxyOptions ,
389+ siteInfo,
390+ } )
374391 }
375392 }
376393
377394 if ( req . proxyOptions . staticFile && isRedirect ( { status : proxyRes . statusCode } ) && proxyRes . headers . location ) {
378395 req . url = proxyRes . headers . location
379- return serveRedirect ( { req, res, proxy : handlers , match : null , options : req . proxyOptions } )
396+ return serveRedirect ( { req, res, proxy : handlers , match : null , options : req . proxyOptions , siteInfo } )
380397 }
381398
382399 const responseData = [ ]
@@ -472,7 +489,11 @@ const initializeProxy = async function ({ configPath, distDir, host, port, proje
472489 return handlers
473490}
474491
475- const onRequest = async ( { addonsUrls, edgeFunctionsProxy, functionsServer, proxy, rewriter, settings } , req , res ) => {
492+ const onRequest = async (
493+ { addonsUrls, edgeFunctionsProxy, functionsServer, proxy, rewriter, settings, siteInfo } ,
494+ req ,
495+ res ,
496+ ) => {
476497 req . originalBody = [ 'GET' , 'OPTIONS' , 'HEAD' ] . includes ( req . method )
477498 ? null
478499 : await createStreamPromise ( req , BYTES_LIMIT )
@@ -509,7 +530,7 @@ const onRequest = async ({ addonsUrls, edgeFunctionsProxy, functionsServer, prox
509530 // We don't want to generate an ETag for 3xx redirects.
510531 req [ shouldGenerateETag ] = ( { statusCode } ) => statusCode < 300 || statusCode >= 400
511532
512- return serveRedirect ( { req, res, proxy, match, options } )
533+ return serveRedirect ( { req, res, proxy, match, options, siteInfo } )
513534 }
514535
515536 // The request will be served by the framework server, which means we want to
@@ -570,6 +591,7 @@ export const startProxy = async function ({
570591 distDir : settings . dist ,
571592 projectDir,
572593 configPath,
594+ siteInfo,
573595 } )
574596
575597 const rewriter = await createRewriter ( {
@@ -588,6 +610,7 @@ export const startProxy = async function ({
588610 addonsUrls,
589611 functionsServer,
590612 edgeFunctionsProxy,
613+ siteInfo,
591614 } )
592615 const primaryServer = settings . https
593616 ? https . createServer ( { cert : settings . https . cert , key : settings . https . key } , onRequestWithOptions )
0 commit comments