netlify-cli 23.13.5 → 23.15.0
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/README.md +1 -1
- package/dist/commands/database/utils.d.ts.map +1 -1
- package/dist/commands/deploy/index.d.ts.map +1 -1
- package/dist/commands/deploy/index.js +2 -1
- package/dist/commands/deploy/index.js.map +1 -1
- package/dist/commands/dev/dev.d.ts.map +1 -1
- package/dist/commands/dev/dev.js +7 -5
- package/dist/commands/dev/dev.js.map +1 -1
- package/dist/commands/dev-exec/dev-exec.d.ts.map +1 -1
- package/dist/commands/dev-exec/dev-exec.js +27 -3
- package/dist/commands/dev-exec/dev-exec.js.map +1 -1
- package/dist/commands/functions/functions-serve.d.ts.map +1 -1
- package/dist/commands/functions/functions-serve.js +5 -1
- package/dist/commands/functions/functions-serve.js.map +1 -1
- package/dist/commands/serve/serve.d.ts.map +1 -1
- package/dist/commands/serve/serve.js +19 -2
- package/dist/commands/serve/serve.js.map +1 -1
- package/dist/lib/edge-functions/proxy.js +2 -2
- package/dist/lib/edge-functions/proxy.js.map +1 -1
- package/dist/lib/edge-functions/registry.d.ts +31 -2
- package/dist/lib/edge-functions/registry.d.ts.map +1 -1
- package/dist/lib/edge-functions/registry.js +46 -4
- package/dist/lib/edge-functions/registry.js.map +1 -1
- package/dist/lib/images/proxy.d.ts +5 -25
- package/dist/lib/images/proxy.d.ts.map +1 -1
- package/dist/lib/images/proxy.js +17 -106
- package/dist/lib/images/proxy.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/dev.d.ts +18 -32
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/dev.js +5 -12
- package/dist/utils/dev.js.map +1 -1
- package/dist/utils/init/utils.d.ts.map +1 -1
- package/dist/utils/init/utils.js +6 -0
- package/dist/utils/init/utils.js.map +1 -1
- package/dist/utils/proxy.d.ts.map +1 -1
- package/dist/utils/proxy.js +7 -2
- package/dist/utils/proxy.js.map +1 -1
- package/dist/utils/types.d.ts +8 -1
- package/dist/utils/types.d.ts.map +1 -1
- package/npm-shrinkwrap.json +1155 -515
- package/package.json +17 -17
|
@@ -1,30 +1,10 @@
|
|
|
1
|
-
import type { IncomingMessage } from 'http';
|
|
2
|
-
import { type
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
+
import { type ImageHandler } from '@netlify/images';
|
|
3
3
|
import type { ServerSettings } from '../../utils/types.d.ts';
|
|
4
4
|
export declare const IMAGE_URL_PATTERN = "/.netlify/images";
|
|
5
|
-
interface QueryParams {
|
|
6
|
-
w?: string;
|
|
7
|
-
width?: string;
|
|
8
|
-
h?: string;
|
|
9
|
-
height?: string;
|
|
10
|
-
q?: string;
|
|
11
|
-
quality?: string;
|
|
12
|
-
fm?: string;
|
|
13
|
-
fit?: string;
|
|
14
|
-
position?: string;
|
|
15
|
-
}
|
|
16
|
-
export declare const parseAllRemoteImages: (config: Pick<NormalizedCachedConfigConfig, "images">) => {
|
|
17
|
-
errors: ErrorObject[];
|
|
18
|
-
remotePatterns: RegExp[];
|
|
19
|
-
};
|
|
20
|
-
interface ErrorObject {
|
|
21
|
-
message: string;
|
|
22
|
-
}
|
|
23
5
|
export declare const isImageRequest: (req: IncomingMessage) => boolean;
|
|
24
|
-
export declare const
|
|
25
|
-
export declare const initializeProxy: ({ config, settings, }: {
|
|
26
|
-
config: NormalizedCachedConfigConfig;
|
|
6
|
+
export declare const initializeProxy: ({ settings, imageHandler, }: {
|
|
27
7
|
settings: ServerSettings;
|
|
28
|
-
|
|
29
|
-
|
|
8
|
+
imageHandler: ImageHandler;
|
|
9
|
+
}) => (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
30
10
|
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../src/lib/images/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../src/lib/images/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAE3D,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAGnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAG5D,eAAO,MAAM,iBAAiB,qBAAqB,CAAA;AAEnD,eAAO,MAAM,cAAc,GAAa,KAAK,eAAe,KAAG,OAE9D,CAAA;AAED,eAAO,MAAM,eAAe,GAAa,6BAGtC;IACD,QAAQ,EAAE,cAAc,CAAA;IACxB,YAAY,EAAE,YAAY,CAAA;CAC3B,MAGe,KAAK,eAAe,EAAE,KAAK,cAAc,kBAkBxD,CAAA"}
|
package/dist/lib/images/proxy.js
CHANGED
|
@@ -1,117 +1,28 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import { createIPX, ipxFSStorage, ipxHttpStorage, createIPXNodeServer } from 'ipx';
|
|
3
|
-
import { log, NETLIFYDEVERR } from '../../utils/command-helpers.js';
|
|
4
1
|
import { getProxyUrl } from '../../utils/proxy.js';
|
|
2
|
+
import { fromWebResponse, toWebRequest } from '@netlify/dev-utils';
|
|
5
3
|
export const IMAGE_URL_PATTERN = '/.netlify/images';
|
|
6
|
-
export const parseAllRemoteImages = function (config) {
|
|
7
|
-
const remotePatterns = [];
|
|
8
|
-
const errors = [];
|
|
9
|
-
const remoteImages = config?.images?.remote_images;
|
|
10
|
-
if (!remoteImages) {
|
|
11
|
-
return { errors, remotePatterns };
|
|
12
|
-
}
|
|
13
|
-
for (const patternString of remoteImages) {
|
|
14
|
-
try {
|
|
15
|
-
const urlRegex = new RegExp(patternString);
|
|
16
|
-
remotePatterns.push(urlRegex);
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
const message = error instanceof Error ? error.message : 'An unknown error occurred';
|
|
20
|
-
errors.push({ message });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return { errors, remotePatterns };
|
|
24
|
-
};
|
|
25
|
-
const getErrorMessage = function ({ message }) {
|
|
26
|
-
return message;
|
|
27
|
-
};
|
|
28
|
-
const handleRemoteImagesErrors = function (errors) {
|
|
29
|
-
if (errors.length === 0) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const errorMessage = errors.map(getErrorMessage).join('\n\n');
|
|
33
|
-
log(NETLIFYDEVERR, `Remote images syntax errors:\n${errorMessage}`);
|
|
34
|
-
};
|
|
35
|
-
const parseRemoteImages = function ({ config }) {
|
|
36
|
-
if (!config) {
|
|
37
|
-
return [];
|
|
38
|
-
}
|
|
39
|
-
const { errors, remotePatterns } = parseAllRemoteImages(config);
|
|
40
|
-
handleRemoteImagesErrors(errors);
|
|
41
|
-
return remotePatterns;
|
|
42
|
-
};
|
|
43
4
|
export const isImageRequest = function (req) {
|
|
44
5
|
return req.url?.startsWith(IMAGE_URL_PATTERN) ?? false;
|
|
45
6
|
};
|
|
46
|
-
export const
|
|
47
|
-
const params = {};
|
|
48
|
-
const width = query.w || query.width || null;
|
|
49
|
-
const height = query.h || query.height || null;
|
|
50
|
-
if (width && height) {
|
|
51
|
-
params.s = `${width}x${height}`;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
params.w = width;
|
|
55
|
-
params.h = height;
|
|
56
|
-
}
|
|
57
|
-
params.quality = query.q || query.quality || null;
|
|
58
|
-
params.format = query.fm || null;
|
|
59
|
-
const fit = query.fit || null;
|
|
60
|
-
params.fit = fit === 'contain' ? 'inside' : fit;
|
|
61
|
-
params.position = query.position || null;
|
|
62
|
-
return Object.entries(params)
|
|
63
|
-
.filter(([, value]) => value !== null)
|
|
64
|
-
.map(([key, value]) => `${key}_${value}`)
|
|
65
|
-
.join(',');
|
|
66
|
-
};
|
|
67
|
-
export const initializeProxy = function ({ config, settings, }) {
|
|
68
|
-
const remoteImages = parseRemoteImages({ config });
|
|
7
|
+
export const initializeProxy = function ({ settings, imageHandler, }) {
|
|
69
8
|
const devServerUrl = getProxyUrl(settings);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const app = express();
|
|
78
|
-
let lastTimeRemoteImagesConfigurationDetailsMessageWasLogged = 0;
|
|
79
|
-
app.use(IMAGE_URL_PATTERN, (req, res) => {
|
|
80
|
-
const { url, ...query } = req.query;
|
|
81
|
-
const sourceImagePath = url;
|
|
82
|
-
const modifiers = transformImageParams(query) || `_`;
|
|
83
|
-
if (!sourceImagePath.startsWith('http://') && !sourceImagePath.startsWith('https://')) {
|
|
84
|
-
// Construct the full URL for relative paths to request from development server
|
|
85
|
-
const sourceImagePathWithLeadingSlash = sourceImagePath.startsWith('/') ? sourceImagePath : `/${sourceImagePath}`;
|
|
86
|
-
const fullImageUrl = `${devServerUrl}${encodeURIComponent(sourceImagePathWithLeadingSlash)}`;
|
|
87
|
-
req.url = `/${modifiers}/${fullImageUrl}`;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
// If the image is remote, we first check if it's allowed by any of patterns
|
|
91
|
-
if (!remoteImages.some((remoteImage) => remoteImage.test(sourceImagePath))) {
|
|
92
|
-
const remoteImageNotAllowedLogMessage = `Remote image "${sourceImagePath}" source for Image CDN is not allowed.`;
|
|
93
|
-
// Contextual information about the remote image configuration is throttled
|
|
94
|
-
// to avoid spamming the console as it's quite verbose
|
|
95
|
-
// Each not allowed remote image will still be logged, just without configuration details
|
|
96
|
-
if (Date.now() - lastTimeRemoteImagesConfigurationDetailsMessageWasLogged > 1000 * 30) {
|
|
97
|
-
log(`${remoteImageNotAllowedLogMessage}\n\n${remoteImages.length === 0
|
|
98
|
-
? 'Currently no remote images are allowed.'
|
|
99
|
-
: `Currently allowed remote images configuration details:\n${remoteImages
|
|
100
|
-
.map((pattern) => ` - ${pattern}`)
|
|
101
|
-
.join('\n')}`}\n\nRefer to https://ntl.fyi/remote-images for information about how to configure allowed remote images.`);
|
|
102
|
-
lastTimeRemoteImagesConfigurationDetailsMessageWasLogged = Date.now();
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
log(remoteImageNotAllowedLogMessage);
|
|
106
|
-
}
|
|
107
|
-
res.status(400).end();
|
|
9
|
+
return async (req, res) => {
|
|
10
|
+
try {
|
|
11
|
+
const webRequest = toWebRequest(req);
|
|
12
|
+
const match = imageHandler.match(webRequest);
|
|
13
|
+
if (!match) {
|
|
14
|
+
res.statusCode = 404;
|
|
15
|
+
res.end('Image not found');
|
|
108
16
|
return;
|
|
109
17
|
}
|
|
110
|
-
|
|
111
|
-
|
|
18
|
+
const response = await match.handle(devServerUrl);
|
|
19
|
+
await fromWebResponse(response, res);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error('Image proxy error:', error);
|
|
23
|
+
res.statusCode = 500;
|
|
24
|
+
res.end('Internal server error');
|
|
112
25
|
}
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
return app;
|
|
26
|
+
};
|
|
116
27
|
};
|
|
117
28
|
//# sourceMappingURL=proxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/lib/images/proxy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/lib/images/proxy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAElE,MAAM,CAAC,MAAM,iBAAiB,GAAG,kBAAkB,CAAA;AAEnD,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,GAAoB;IAC1D,OAAO,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,iBAA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