netlify-cli 12.9.0 → 12.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/utils/proxy.mjs +24 -12
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "netlify-cli",
|
|
3
|
-
"version": "12.9.
|
|
3
|
+
"version": "12.9.1",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "netlify-cli",
|
|
9
|
-
"version": "12.9.
|
|
9
|
+
"version": "12.9.1",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
package/package.json
CHANGED
package/src/utils/proxy.mjs
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
import { fileExistsAsync, isFileAsync } from '../lib/fs.mjs'
|
|
30
30
|
import renderErrorTemplate from '../lib/render-error-template.mjs'
|
|
31
31
|
|
|
32
|
-
import { NETLIFYDEVLOG, NETLIFYDEVWARN } from './command-helpers.mjs'
|
|
32
|
+
import { NETLIFYDEVLOG, NETLIFYDEVWARN, log, chalk } from './command-helpers.mjs'
|
|
33
33
|
import createStreamPromise from './create-stream-promise.mjs'
|
|
34
34
|
import { headersForPath, parseHeaders } from './headers.mjs'
|
|
35
35
|
import { createRewriter, onChanges } from './rules-proxy.mjs'
|
|
@@ -144,7 +144,7 @@ const alternativePathsFor = function (url) {
|
|
|
144
144
|
return paths
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
const serveRedirect = async function ({ match, options, proxy, req, res, siteInfo }) {
|
|
147
|
+
const serveRedirect = async function ({ env, match, options, proxy, req, res, siteInfo }) {
|
|
148
148
|
if (!match) return proxy.web(req, res, options)
|
|
149
149
|
|
|
150
150
|
options = options || req.proxyOptions || {}
|
|
@@ -157,12 +157,21 @@ const serveRedirect = async function ({ match, options, proxy, req, res, siteInf
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
if (match.signingSecret) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
const signingSecretVar = env[match.signingSecret]
|
|
161
|
+
|
|
162
|
+
if (signingSecretVar) {
|
|
163
|
+
req.headers['x-nf-sign'] = signRedirect({
|
|
164
|
+
deployContext: 'dev',
|
|
165
|
+
secret: signingSecretVar.value,
|
|
166
|
+
siteID: siteInfo.id,
|
|
167
|
+
siteURL: siteInfo.url,
|
|
168
|
+
})
|
|
169
|
+
} else {
|
|
170
|
+
log(
|
|
171
|
+
NETLIFYDEVWARN,
|
|
172
|
+
`Could not sign redirect because environment variable ${chalk.yellow(match.signingSecret)} is not set`,
|
|
173
|
+
)
|
|
174
|
+
}
|
|
166
175
|
}
|
|
167
176
|
|
|
168
177
|
if (isFunction(options.functionsPort, req.url)) {
|
|
@@ -316,7 +325,7 @@ const reqToURL = function (req, pathname) {
|
|
|
316
325
|
|
|
317
326
|
const MILLISEC_TO_SEC = 1e3
|
|
318
327
|
|
|
319
|
-
const initializeProxy = async function ({ configPath, distDir, host, port, projectDir, siteInfo }) {
|
|
328
|
+
const initializeProxy = async function ({ configPath, distDir, env, host, port, projectDir, siteInfo }) {
|
|
320
329
|
const proxy = httpProxy.createProxyServer({
|
|
321
330
|
selfHandleResponse: true,
|
|
322
331
|
target: {
|
|
@@ -387,13 +396,14 @@ const initializeProxy = async function ({ configPath, distDir, host, port, proje
|
|
|
387
396
|
match: req.proxyOptions.match,
|
|
388
397
|
options: req.proxyOptions,
|
|
389
398
|
siteInfo,
|
|
399
|
+
env,
|
|
390
400
|
})
|
|
391
401
|
}
|
|
392
402
|
}
|
|
393
403
|
|
|
394
404
|
if (req.proxyOptions.staticFile && isRedirect({ status: proxyRes.statusCode }) && proxyRes.headers.location) {
|
|
395
405
|
req.url = proxyRes.headers.location
|
|
396
|
-
return serveRedirect({ req, res, proxy: handlers, match: null, options: req.proxyOptions, siteInfo })
|
|
406
|
+
return serveRedirect({ req, res, proxy: handlers, match: null, options: req.proxyOptions, siteInfo, env })
|
|
397
407
|
}
|
|
398
408
|
|
|
399
409
|
const responseData = []
|
|
@@ -490,7 +500,7 @@ const initializeProxy = async function ({ configPath, distDir, host, port, proje
|
|
|
490
500
|
}
|
|
491
501
|
|
|
492
502
|
const onRequest = async (
|
|
493
|
-
{ addonsUrls, edgeFunctionsProxy, functionsServer, proxy, rewriter, settings, siteInfo },
|
|
503
|
+
{ addonsUrls, edgeFunctionsProxy, env, functionsServer, proxy, rewriter, settings, siteInfo },
|
|
494
504
|
req,
|
|
495
505
|
res,
|
|
496
506
|
) => {
|
|
@@ -530,7 +540,7 @@ const onRequest = async (
|
|
|
530
540
|
// We don't want to generate an ETag for 3xx redirects.
|
|
531
541
|
req[shouldGenerateETag] = ({ statusCode }) => statusCode < 300 || statusCode >= 400
|
|
532
542
|
|
|
533
|
-
return serveRedirect({ req, res, proxy, match, options, siteInfo })
|
|
543
|
+
return serveRedirect({ req, res, proxy, match, options, siteInfo, env })
|
|
534
544
|
}
|
|
535
545
|
|
|
536
546
|
// The request will be served by the framework server, which means we want to
|
|
@@ -586,6 +596,7 @@ export const startProxy = async function ({
|
|
|
586
596
|
state,
|
|
587
597
|
})
|
|
588
598
|
const proxy = await initializeProxy({
|
|
599
|
+
env,
|
|
589
600
|
host: settings.frameworkHost,
|
|
590
601
|
port: settings.frameworkPort,
|
|
591
602
|
distDir: settings.dist,
|
|
@@ -611,6 +622,7 @@ export const startProxy = async function ({
|
|
|
611
622
|
functionsServer,
|
|
612
623
|
edgeFunctionsProxy,
|
|
613
624
|
siteInfo,
|
|
625
|
+
env,
|
|
614
626
|
})
|
|
615
627
|
const primaryServer = settings.https
|
|
616
628
|
? https.createServer({ cert: settings.https.cert, key: settings.https.key }, onRequestWithOptions)
|