netlify 27.16.2 → 27.17.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/dist/commands/base-command.d.ts +1 -1
- package/dist/commands/deploy/deploy.js +0 -1
- package/dist/commands/init/init.js +73 -6
- package/dist/commands/logs/sources/server.js +11 -2
- package/dist/utils/deploy/deploy-site.d.ts +1 -2
- package/dist/utils/deploy/deploy-site.js +1 -2
- package/dist/utils/deploy/hash-fns.d.ts +1 -2
- package/dist/utils/deploy/hash-fns.js +6 -11
- package/dist/utils/get-repo-data.d.ts +6 -3
- package/dist/utils/get-repo-data.js +18 -8
- package/dist/utils/proxy.js +54 -65
- package/package.json +4 -4
|
@@ -66,7 +66,7 @@ export default class BaseCommand extends Command {
|
|
|
66
66
|
/** Will be called on the end of an action to track the metrics */
|
|
67
67
|
onEnd(error_?: unknown): Promise<undefined>;
|
|
68
68
|
authenticate(tokenFromFlag?: string): Promise<string>;
|
|
69
|
-
|
|
69
|
+
refreshAccounts(): Promise<void>;
|
|
70
70
|
expensivelyAuthenticate(): Promise<string>;
|
|
71
71
|
/** Adds some data to the analytics payload */
|
|
72
72
|
setAnalyticsPayload(payload: Record<string, unknown>): void;
|
|
@@ -461,7 +461,6 @@ const runDeploy = async ({ alias, api, command, config, deployFolder, deployTime
|
|
|
461
461
|
workingDir: command.workingDir,
|
|
462
462
|
manifestPath: manifestPath ?? undefined,
|
|
463
463
|
packagePath,
|
|
464
|
-
serverEnabled: Boolean(siteData.feature_flags?.netlify_build_server_standalone),
|
|
465
464
|
serverManifestPath: serverManifestPath ?? undefined,
|
|
466
465
|
skipFunctionsCache,
|
|
467
466
|
siteRoot: site.root,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { confirm, select } from '@inquirer/prompts';
|
|
2
2
|
import { isEmpty } from '../../utils/object-utilities.js';
|
|
3
|
-
import { chalk, exit, log, netlifyCommand } from '../../utils/command-helpers.js';
|
|
3
|
+
import { chalk, exit, log, logAndThrowError, netlifyCommand, warn } from '../../utils/command-helpers.js';
|
|
4
4
|
import getRepoData from '../../utils/get-repo-data.js';
|
|
5
5
|
import { ensureNetlifyIgnore } from '../../utils/gitignore.js';
|
|
6
6
|
import { configureRepo } from '../../utils/init/config.js';
|
|
@@ -30,6 +30,71 @@ const logExistingAndExit = ({ siteInfo }) => {
|
|
|
30
30
|
log(`2. Then run ${chalk.cyanBright.bold(`${netlifyCommand()} init`)} again`);
|
|
31
31
|
return exit();
|
|
32
32
|
};
|
|
33
|
+
const logLinkedWithoutGitAndExit = ({ siteInfo, repoError, }) => {
|
|
34
|
+
if (repoError.reason !== 'no-remote') {
|
|
35
|
+
warn(`Could not read the git remote: ${repoError.error}`);
|
|
36
|
+
log(`Fix the git remote, then run ${chalk.cyanBright.bold(`${netlifyCommand()} init`)} again to connect it.`);
|
|
37
|
+
}
|
|
38
|
+
log();
|
|
39
|
+
log(`This folder is already linked to the Netlify project ${chalk.cyan(siteInfo.name)}`);
|
|
40
|
+
log();
|
|
41
|
+
log(`Project Url: ${chalk.cyan(siteInfo.ssl_url || siteInfo.url)}`);
|
|
42
|
+
log();
|
|
43
|
+
log(`To deploy to this project, run ${chalk.cyanBright.bold(`${netlifyCommand()} deploy`)}.`);
|
|
44
|
+
log(`To link this folder to a different project, run ${chalk.cyanBright.bold(`${netlifyCommand()} unlink`)}, then ${chalk.cyanBright.bold(`${netlifyCommand()} init`)}.`);
|
|
45
|
+
return exit();
|
|
46
|
+
};
|
|
47
|
+
const ignoreLinkedSiteForThisRun = (command) => {
|
|
48
|
+
const { site } = command.netlify;
|
|
49
|
+
command.siteId = undefined;
|
|
50
|
+
command.netlify.siteInfo = {};
|
|
51
|
+
command.netlify.site = {
|
|
52
|
+
root: site.root,
|
|
53
|
+
configPath: site.configPath,
|
|
54
|
+
get id() {
|
|
55
|
+
return command.siteId;
|
|
56
|
+
},
|
|
57
|
+
set id(id) {
|
|
58
|
+
site.id = id;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
const getLinkedSiteInfo = async (command) => {
|
|
63
|
+
const { api, siteInfo } = command.netlify;
|
|
64
|
+
if (isEmpty(siteInfo)) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
if (siteInfo.name) {
|
|
68
|
+
return siteInfo;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
return (await api.getSite({ siteId: siteInfo.id }));
|
|
72
|
+
}
|
|
73
|
+
catch (error_) {
|
|
74
|
+
const { status, message } = error_;
|
|
75
|
+
const unusableLinks = {
|
|
76
|
+
403: {
|
|
77
|
+
reason: 'forbidden',
|
|
78
|
+
warning: `You don't have access to the Netlify project ${siteInfo.id} linked to this folder. Continuing without it.`,
|
|
79
|
+
},
|
|
80
|
+
404: {
|
|
81
|
+
reason: 'not_found',
|
|
82
|
+
warning: `The Netlify project ${siteInfo.id} linked to this folder no longer exists. Continuing without it.`,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
const unusableLink = unusableLinks[status];
|
|
86
|
+
if (unusableLink === undefined) {
|
|
87
|
+
return logAndThrowError(`Could not load the Netlify project ${siteInfo.id} linked to this folder (${status ? `status ${status.toString()}` : message}). Try again, or run ${chalk.cyanBright.bold(`${netlifyCommand()} unlink`)} to start over.`);
|
|
88
|
+
}
|
|
89
|
+
warn(unusableLink.warning);
|
|
90
|
+
await track('sites_unlinked', { siteId: siteInfo.id, kind: 'init', reason: unusableLink.reason });
|
|
91
|
+
ignoreLinkedSiteForThisRun(command);
|
|
92
|
+
if (command.netlify.accounts.length === 0) {
|
|
93
|
+
await command.refreshAccounts();
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
33
98
|
/**
|
|
34
99
|
* Creates and new site and exits the process
|
|
35
100
|
*/
|
|
@@ -167,7 +232,6 @@ export const init = async (options, command, { customizeExitMessage, exitAfterCo
|
|
|
167
232
|
resetContext: options.resetContext,
|
|
168
233
|
});
|
|
169
234
|
const { repositoryRoot, state } = command.netlify;
|
|
170
|
-
const { siteInfo: existingSiteInfo } = command.netlify;
|
|
171
235
|
// Check logged in status
|
|
172
236
|
await command.authenticate();
|
|
173
237
|
// Add .netlify to .gitignore file
|
|
@@ -175,13 +239,16 @@ export const init = async (options, command, { customizeExitMessage, exitAfterCo
|
|
|
175
239
|
if (shouldSetupAgentSkills) {
|
|
176
240
|
await installAgentSkills(command, resetContext);
|
|
177
241
|
}
|
|
178
|
-
const
|
|
179
|
-
if (
|
|
180
|
-
logExistingAndExit({ siteInfo:
|
|
242
|
+
const linkedSiteInfo = await getLinkedSiteInfo(command);
|
|
243
|
+
if (linkedSiteInfo && getRepoUrl(linkedSiteInfo) && !options.force) {
|
|
244
|
+
logExistingAndExit({ siteInfo: linkedSiteInfo });
|
|
181
245
|
}
|
|
182
246
|
// Look for local repo
|
|
183
247
|
const repoData = await getRepoData({ workingDir: command.workingDir, remoteName: options.gitRemoteName });
|
|
184
248
|
if ('error' in repoData) {
|
|
249
|
+
if (linkedSiteInfo) {
|
|
250
|
+
return logLinkedWithoutGitAndExit({ siteInfo: linkedSiteInfo, repoError: repoData });
|
|
251
|
+
}
|
|
185
252
|
// TODO(ndhoule): Custom error messaage here
|
|
186
253
|
return await handleNoGitRemoteAndExit({
|
|
187
254
|
command,
|
|
@@ -191,7 +258,7 @@ export const init = async (options, command, { customizeExitMessage, exitAfterCo
|
|
|
191
258
|
customizeExitMessage,
|
|
192
259
|
});
|
|
193
260
|
}
|
|
194
|
-
const siteInfo =
|
|
261
|
+
const siteInfo = linkedSiteInfo ?? (await createOrLinkSiteToRepo(command));
|
|
195
262
|
log();
|
|
196
263
|
// Check for existing CI setup
|
|
197
264
|
const remoteBuildRepo = getRepoUrl(siteInfo);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { debugFetch } from '../log-api.js';
|
|
2
|
-
// The API serves up to 500 lines a page
|
|
2
|
+
// The API serves up to 500 lines a page. MAX_PAGES bounds the pages read, so
|
|
3
|
+
// a long window doesn't page without end.
|
|
3
4
|
const PER_PAGE = 500;
|
|
4
5
|
const MAX_PAGES = 1 + 10_000 / PER_PAGE;
|
|
5
6
|
// Lines are stored a few seconds after their time, so each poll looks back
|
|
@@ -41,11 +42,18 @@ const fetchServerLogLines = async ({ apiBase, siteId, accessToken, from, to, lev
|
|
|
41
42
|
// orders by finer ones, so reversing is what keeps same-millisecond lines in order.
|
|
42
43
|
const lines = [];
|
|
43
44
|
const severity = severityFor(levels);
|
|
45
|
+
// An API that sends no cursor is paged by number.
|
|
46
|
+
let cursor;
|
|
44
47
|
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
45
48
|
const url = new URL(`${apiBase}/sites/${encodeURIComponent(siteId)}/observability/server/logs`);
|
|
46
49
|
url.searchParams.set('from_ts', String(from));
|
|
47
50
|
url.searchParams.set('to_ts', String(to));
|
|
48
|
-
|
|
51
|
+
if (cursor) {
|
|
52
|
+
url.searchParams.set('cursor', cursor);
|
|
53
|
+
}
|
|
54
|
+
else if (page > 1) {
|
|
55
|
+
url.searchParams.set('page', String(page));
|
|
56
|
+
}
|
|
49
57
|
url.searchParams.set('per_page', String(PER_PAGE));
|
|
50
58
|
if (severity) {
|
|
51
59
|
url.searchParams.set('severity', severity);
|
|
@@ -63,6 +71,7 @@ const fetchServerLogLines = async ({ apiBase, siteId, accessToken, from, to, lev
|
|
|
63
71
|
if (!body.has_next_page) {
|
|
64
72
|
return { lines: lines.reverse(), truncated: false };
|
|
65
73
|
}
|
|
74
|
+
cursor = body.next_cursor;
|
|
66
75
|
}
|
|
67
76
|
return { lines: lines.reverse(), truncated: true };
|
|
68
77
|
};
|
|
@@ -23,7 +23,6 @@ export interface DeploySiteOptions {
|
|
|
23
23
|
manifestPath?: string | undefined;
|
|
24
24
|
maxRetry?: number;
|
|
25
25
|
packagePath?: string | undefined;
|
|
26
|
-
serverEnabled?: boolean;
|
|
27
26
|
serverManifestPath?: string | undefined;
|
|
28
27
|
siteRoot?: string | undefined;
|
|
29
28
|
skipFunctionsCache?: boolean | undefined;
|
|
@@ -32,7 +31,7 @@ export interface DeploySiteOptions {
|
|
|
32
31
|
tmpDir?: string;
|
|
33
32
|
workingDir: string;
|
|
34
33
|
}
|
|
35
|
-
export declare const deploySite: (command: BaseCommand, api: NetlifyAPI, siteId: string, dir: string, { branch, concurrentHash, concurrentUpload, config, deployId, deployTimeout, draft, environment, filter, fnDir, functionsConfig, hashAlgorithm, manifestPath, maxRetry, packagePath,
|
|
34
|
+
export declare const deploySite: (command: BaseCommand, api: NetlifyAPI, siteId: string, dir: string, { branch, concurrentHash, concurrentUpload, config, deployId, deployTimeout, draft, environment, filter, fnDir, functionsConfig, hashAlgorithm, manifestPath, maxRetry, packagePath, serverManifestPath, siteRoot, skipFunctionsCache, statusCb, syncFileLimit, tmpDir, workingDir, }: DeploySiteOptions) => Promise<{
|
|
36
35
|
deployId: string;
|
|
37
36
|
deploy: import("./util.js").ReadyDeploy;
|
|
38
37
|
uploadList: (import("./upload-files.js").EdgeFunctionUploadFile | import("./upload-files.js").ServerUploadFile | File | (import("./upload-files.js").FunctionUploadFile & {
|
|
@@ -18,7 +18,7 @@ const buildStatsString = (possibleParts) => {
|
|
|
18
18
|
}
|
|
19
19
|
return `${parts.slice(0, -1).join(', ')} and ${parts[parts.length - 1]}`;
|
|
20
20
|
};
|
|
21
|
-
export const deploySite = async (command, api, siteId, dir, { branch, concurrentHash = DEFAULT_CONCURRENT_HASH, concurrentUpload = DEFAULT_CONCURRENT_UPLOAD, config, deployId, deployTimeout = DEFAULT_DEPLOY_TIMEOUT, draft = false, environment, filter, fnDir = [], functionsConfig, hashAlgorithm, manifestPath, maxRetry = DEFAULT_MAX_RETRY, packagePath,
|
|
21
|
+
export const deploySite = async (command, api, siteId, dir, { branch, concurrentHash = DEFAULT_CONCURRENT_HASH, concurrentUpload = DEFAULT_CONCURRENT_UPLOAD, config, deployId, deployTimeout = DEFAULT_DEPLOY_TIMEOUT, draft = false, environment, filter, fnDir = [], functionsConfig, hashAlgorithm, manifestPath, maxRetry = DEFAULT_MAX_RETRY, packagePath, serverManifestPath, siteRoot, skipFunctionsCache, statusCb = () => {
|
|
22
22
|
/* default to noop */
|
|
23
23
|
}, syncFileLimit = DEFAULT_SYNC_LIMIT, tmpDir = temporaryDirectory(), workingDir, }) => {
|
|
24
24
|
statusCb({
|
|
@@ -47,7 +47,6 @@ export const deploySite = async (command, api, siteId, dir, { branch, concurrent
|
|
|
47
47
|
manifestPath,
|
|
48
48
|
packagePath,
|
|
49
49
|
serverConfig: config.server,
|
|
50
|
-
serverEnabled,
|
|
51
50
|
serverManifestPath,
|
|
52
51
|
skipFunctionsCache,
|
|
53
52
|
rootDir: siteRoot,
|
|
@@ -45,7 +45,7 @@ declare const toFunctionConfigPayload: (func: FunctionResult) => {
|
|
|
45
45
|
vcpu: number | undefined;
|
|
46
46
|
};
|
|
47
47
|
type FunctionConfigPayload = ReturnType<typeof toFunctionConfigPayload>;
|
|
48
|
-
declare const hashFns: (command: BaseCommand, directories: string[], { concurrentHash, functionsConfig, hashAlgorithm, manifestPath, packagePath, rootDir, serverConfig,
|
|
48
|
+
declare const hashFns: (command: BaseCommand, directories: string[], { concurrentHash, functionsConfig, hashAlgorithm, manifestPath, packagePath, rootDir, serverConfig, serverManifestPath, skipFunctionsCache, statusCb, tmpDir, }: {
|
|
49
49
|
concurrentHash?: number;
|
|
50
50
|
functionsConfig?: FunctionsConfig | undefined;
|
|
51
51
|
hashAlgorithm?: string | undefined;
|
|
@@ -53,7 +53,6 @@ declare const hashFns: (command: BaseCommand, directories: string[], { concurren
|
|
|
53
53
|
packagePath?: string | undefined;
|
|
54
54
|
rootDir?: string | undefined;
|
|
55
55
|
serverConfig?: NetlifyServerConfig | undefined;
|
|
56
|
-
serverEnabled?: boolean | undefined;
|
|
57
56
|
serverManifestPath?: string | undefined;
|
|
58
57
|
skipFunctionsCache?: boolean | undefined;
|
|
59
58
|
statusCb: StatusCallback;
|
|
@@ -52,10 +52,7 @@ const getFunctionZips = async ({ command, directories, functionsConfig, manifest
|
|
|
52
52
|
config: functionsConfig,
|
|
53
53
|
});
|
|
54
54
|
};
|
|
55
|
-
const getServerBundle = async ({ packagePath, rootDir, serverConfig,
|
|
56
|
-
if (!serverEnabled) {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
55
|
+
const getServerBundle = async ({ packagePath, rootDir, serverConfig, serverManifestPath, tmpDir, }) => {
|
|
59
56
|
if (serverManifestPath) {
|
|
60
57
|
try {
|
|
61
58
|
const { server, timestamp } = JSON.parse(await readFile(serverManifestPath, 'utf-8'));
|
|
@@ -105,12 +102,7 @@ const toFunctionConfigPayload = (func) => ({
|
|
|
105
102
|
traffic_rules: trafficRulesConfig(func.trafficRules),
|
|
106
103
|
vcpu: func.vcpu,
|
|
107
104
|
});
|
|
108
|
-
const hashFns = async (command, directories, { concurrentHash, functionsConfig, hashAlgorithm = 'sha256', manifestPath, packagePath, rootDir, serverConfig,
|
|
109
|
-
// Exit early if there is nothing to bundle. A site can have a server without
|
|
110
|
-
// any functions directory.
|
|
111
|
-
if (directories.length === 0 && !serverEnabled) {
|
|
112
|
-
return { functions: {}, functionsWithNativeModules: [] };
|
|
113
|
-
}
|
|
105
|
+
const hashFns = async (command, directories, { concurrentHash, functionsConfig, hashAlgorithm = 'sha256', manifestPath, packagePath, rootDir, serverConfig, serverManifestPath, skipFunctionsCache, statusCb, tmpDir, }) => {
|
|
114
106
|
const [functionZips, serverBundle] = await Promise.all([
|
|
115
107
|
directories.length === 0
|
|
116
108
|
? []
|
|
@@ -124,8 +116,11 @@ const hashFns = async (command, directories, { concurrentHash, functionsConfig,
|
|
|
124
116
|
statusCb,
|
|
125
117
|
tmpDir,
|
|
126
118
|
}),
|
|
127
|
-
getServerBundle({ packagePath, rootDir, serverConfig,
|
|
119
|
+
getServerBundle({ packagePath, rootDir, serverConfig, serverManifestPath, tmpDir }),
|
|
128
120
|
]);
|
|
121
|
+
if (directories.length === 0 && serverBundle === undefined) {
|
|
122
|
+
return { functions: {}, functionsWithNativeModules: [] };
|
|
123
|
+
}
|
|
129
124
|
// ZISI's in-memory FunctionResult only nests bootstrap/runtime version into
|
|
130
125
|
// buildData when writing the manifest cache. Reconstruct it for direct-zip paths.
|
|
131
126
|
for (const func of functionZips) {
|
|
@@ -7,11 +7,14 @@ export interface RepoData {
|
|
|
7
7
|
provider: string | null;
|
|
8
8
|
httpsUrl: string;
|
|
9
9
|
}
|
|
10
|
+
export type RepoDataErrorReason = 'no-remote' | 'unknown-remote' | 'invalid-url' | 'unreadable';
|
|
11
|
+
export interface RepoDataError {
|
|
12
|
+
error: string;
|
|
13
|
+
reason: RepoDataErrorReason;
|
|
14
|
+
}
|
|
10
15
|
declare const getRepoData: ({ remoteName, workingDir, }: {
|
|
11
16
|
remoteName?: string;
|
|
12
17
|
workingDir: string;
|
|
13
|
-
}) => Promise<RepoData |
|
|
14
|
-
error: string;
|
|
15
|
-
}>;
|
|
18
|
+
}) => Promise<RepoData | RepoDataError>;
|
|
16
19
|
export default getRepoData;
|
|
17
20
|
//# sourceMappingURL=get-repo-data.d.ts.map
|
|
@@ -5,14 +5,23 @@ import gitRepoInfo from 'git-repo-info';
|
|
|
5
5
|
import gitconfiglocal from 'gitconfiglocal';
|
|
6
6
|
import parseGithubUrl from 'parse-github-url';
|
|
7
7
|
import { log } from './command-helpers.js';
|
|
8
|
+
class RepoDataLookupError extends Error {
|
|
9
|
+
reason;
|
|
10
|
+
constructor(message, reason) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.reason = reason;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const redactCredentials = (url) => url.replace(/\/\/[^/@]*@/, '//***@');
|
|
8
16
|
const getRepoData = async ({ remoteName, workingDir, }) => {
|
|
9
17
|
try {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
const gitDirectory = await findUp('.git', { cwd: workingDir, type: 'directory' });
|
|
19
|
+
if (!gitDirectory) {
|
|
20
|
+
throw new RepoDataLookupError('No Git remote found', 'no-remote');
|
|
21
|
+
}
|
|
22
|
+
const gitConfig = await util.promisify(gitconfiglocal)(workingDir);
|
|
23
|
+
if (!gitConfig?.remote || Object.keys(gitConfig.remote).length === 0) {
|
|
24
|
+
throw new RepoDataLookupError('No Git remote found', 'no-remote');
|
|
16
25
|
}
|
|
17
26
|
const baseGitPath = dirname(gitDirectory);
|
|
18
27
|
if (workingDir !== baseGitPath) {
|
|
@@ -25,13 +34,13 @@ const getRepoData = async ({ remoteName, workingDir, }) => {
|
|
|
25
34
|
if (!Object.prototype.hasOwnProperty.call(gitConfig.remote, remoteName) ||
|
|
26
35
|
!gitConfig.remote[remoteName] ||
|
|
27
36
|
Object.keys(gitConfig.remote[remoteName]).length === 0) {
|
|
28
|
-
throw new
|
|
37
|
+
throw new RepoDataLookupError(`The specified remote "${remoteName}" is not defined in Git repo. Please use --git-remote-name flag to specify a remote.`, 'unknown-remote');
|
|
29
38
|
}
|
|
30
39
|
const { url } = gitConfig.remote[remoteName];
|
|
31
40
|
const parsedUrl = parseGithubUrl(url);
|
|
32
41
|
// TODO(serhalp): Validate more aggressively? We should probably require `owner`, `repo`, `host`?
|
|
33
42
|
if (parsedUrl == null) {
|
|
34
|
-
throw new
|
|
43
|
+
throw new RepoDataLookupError(`The specified Git remote ${remoteName} is not a valid URL: ${redactCredentials(String(url))}`, 'invalid-url');
|
|
35
44
|
}
|
|
36
45
|
const { host, name, owner, repo } = parsedUrl;
|
|
37
46
|
const { branch } = gitRepoInfo();
|
|
@@ -48,6 +57,7 @@ const getRepoData = async ({ remoteName, workingDir, }) => {
|
|
|
48
57
|
catch (error) {
|
|
49
58
|
return {
|
|
50
59
|
error: error instanceof Error ? error.message : (error?.toString() ?? 'Failed to get repo data'),
|
|
60
|
+
reason: error instanceof RepoDataLookupError ? error.reason : 'unreadable',
|
|
51
61
|
};
|
|
52
62
|
}
|
|
53
63
|
};
|
package/dist/utils/proxy.js
CHANGED
|
@@ -596,42 +596,40 @@ const onRequest = async ({ api, edgeFunctionsProxy, env, functionsRegistry, func
|
|
|
596
596
|
}
|
|
597
597
|
return proxy.web(req, res, { headers, target: functionsServer });
|
|
598
598
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
headers.append(req.rawHeaders[index], req.rawHeaders[index + 1]);
|
|
609
|
-
}
|
|
610
|
-
// The server handler gets a `Request` with no socket, so it reads the
|
|
611
|
-
// client's address from this header to set `context.ip`.
|
|
612
|
-
headers.set('x-forwarded-for', req.socket.remoteAddress ?? '');
|
|
613
|
-
const response = await serverMatch.handle(new Request(requestURL, {
|
|
614
|
-
body: req.originalBody,
|
|
615
|
-
headers,
|
|
616
|
-
method: req.method,
|
|
617
|
-
}));
|
|
618
|
-
await fromWebResponse(response, res);
|
|
619
|
-
return;
|
|
599
|
+
try {
|
|
600
|
+
const requestURL = reqToURL(req, req.url);
|
|
601
|
+
const serverMatch = await serverHandler.match(new Request(requestURL));
|
|
602
|
+
if (serverMatch) {
|
|
603
|
+
const staticFile = await getStatic(decodeURIComponent(requestURL.pathname), settings.dist ?? '');
|
|
604
|
+
if (!staticFile) {
|
|
605
|
+
const headers = new Headers();
|
|
606
|
+
for (let index = 0; index < req.rawHeaders.length; index += 2) {
|
|
607
|
+
headers.append(req.rawHeaders[index], req.rawHeaders[index + 1]);
|
|
620
608
|
}
|
|
609
|
+
// The server handler gets a `Request` with no socket, so it reads the
|
|
610
|
+
// client's address from this header to set `context.ip`.
|
|
611
|
+
headers.set('x-forwarded-for', req.socket.remoteAddress ?? '');
|
|
612
|
+
const response = await serverMatch.handle(new Request(requestURL, {
|
|
613
|
+
body: req.originalBody,
|
|
614
|
+
headers,
|
|
615
|
+
method: req.method,
|
|
616
|
+
}));
|
|
617
|
+
await fromWebResponse(response, res);
|
|
618
|
+
return;
|
|
621
619
|
}
|
|
622
620
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
else {
|
|
630
|
-
res.writeHead(500);
|
|
631
|
-
res.end(error instanceof Error ? error.message : 'Failed to serve request from Netlify Server');
|
|
632
|
-
}
|
|
633
|
-
return;
|
|
621
|
+
}
|
|
622
|
+
catch (error) {
|
|
623
|
+
// The response may have failed mid-stream, in which case the head is
|
|
624
|
+
// out and the only remaining option is dropping the connection.
|
|
625
|
+
if (res.headersSent) {
|
|
626
|
+
res.destroy();
|
|
634
627
|
}
|
|
628
|
+
else {
|
|
629
|
+
res.writeHead(500);
|
|
630
|
+
res.end(error instanceof Error ? error.message : 'Failed to serve request from Netlify Server');
|
|
631
|
+
}
|
|
632
|
+
return;
|
|
635
633
|
}
|
|
636
634
|
const match = await rewriter(req);
|
|
637
635
|
const options = {
|
|
@@ -721,26 +719,19 @@ export const startProxy = async function ({ accountId, aiGatewayContext, api, bl
|
|
|
721
719
|
logger: { log, warn, error: logError },
|
|
722
720
|
imagesConfig: config.images,
|
|
723
721
|
});
|
|
724
|
-
const
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
});
|
|
738
|
-
const handlerToStop = serverHandler;
|
|
739
|
-
runBeforeProcessExit(async () => {
|
|
740
|
-
await handlerToStop.stop();
|
|
741
|
-
await serverFileWatcher.close();
|
|
742
|
-
});
|
|
743
|
-
}
|
|
722
|
+
const serverFileWatcher = new FileWatcher();
|
|
723
|
+
const serverHandler = new ServerHandler({
|
|
724
|
+
accountID: siteInfo?.account_id,
|
|
725
|
+
fileWatcher: serverFileWatcher,
|
|
726
|
+
geolocation: mockLocation,
|
|
727
|
+
logger: { log, warn, error: logError },
|
|
728
|
+
projectRoot: projectDir,
|
|
729
|
+
siteID: siteInfo?.id,
|
|
730
|
+
});
|
|
731
|
+
runBeforeProcessExit(async () => {
|
|
732
|
+
await serverHandler.stop();
|
|
733
|
+
await serverFileWatcher.close();
|
|
734
|
+
});
|
|
744
735
|
const imageProxy = initializeImageProxy({
|
|
745
736
|
settings,
|
|
746
737
|
imageHandler,
|
|
@@ -794,19 +785,17 @@ export const startProxy = async function ({ accountId, aiGatewayContext, api, bl
|
|
|
794
785
|
? https.createServer({ cert: settings.https.cert, key: settings.https.key }, onRequestWithOptions)
|
|
795
786
|
: http.createServer(onRequestWithOptions);
|
|
796
787
|
const onUpgrade = async function onUpgrade(req, socket, head) {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
return;
|
|
809
|
-
}
|
|
788
|
+
let handled = false;
|
|
789
|
+
try {
|
|
790
|
+
handled = await serverHandler.handleUpgrade(req, socket, head);
|
|
791
|
+
}
|
|
792
|
+
catch (error) {
|
|
793
|
+
logError(`Failed to hand over upgrade request to server: ${error instanceof Error ? error.message : String(error)}`);
|
|
794
|
+
socket.destroy();
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
if (handled) {
|
|
798
|
+
return;
|
|
810
799
|
}
|
|
811
800
|
const match = await rewriter(req);
|
|
812
801
|
if (match && isExternal(match)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "netlify",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.17.0",
|
|
4
4
|
"description": "Netlify command line tool",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
"@fastify/static": "^10.0.0",
|
|
55
55
|
"@inquirer/prompts": "^8.7.2",
|
|
56
56
|
"@netlify/ai": "^1.0.2",
|
|
57
|
-
"@netlify/api": "^15.1.
|
|
57
|
+
"@netlify/api": "^15.1.6",
|
|
58
58
|
"@netlify/blobs": "^11.1.7",
|
|
59
|
-
"@netlify/build": "^37.7.
|
|
59
|
+
"@netlify/build": "^37.7.6",
|
|
60
60
|
"@netlify/build-info": "^11.3.1",
|
|
61
|
-
"@netlify/config": "^25.
|
|
61
|
+
"@netlify/config": "^25.6.2",
|
|
62
62
|
"@netlify/dev": "^5.1.12",
|
|
63
63
|
"@netlify/dev-utils": "^6.0.4",
|
|
64
64
|
"@netlify/edge-bundler": "^16.2.0",
|