Compare commits

..

29 Commits

Author SHA1 Message Date
JJ Kasper
f5f276021e Publish Canary
- @vercel/next@2.7.3-canary.0
2020-11-19 14:30:56 -06:00
JJ Kasper
9fbec823f3 [next] Ensure public files are matched with i18n domains (#5447)
This makes sure we strip all locales during the `handle: 'miss'` phase to allow locale domains to match public files correctly. This also updates the trailing slash redirect handling to match the behavior for `.well-known` added in https://github.com/vercel/vercel/pull/5407

We aren't able to add tests for locale domains with the current test flow yet since they require domains be assigned although the changes in this PR was tested manually against http://i18n-support.vercel.app/ with `@ijjk/now-next@0.1.3-i18n`

x-ref: https://github.com/vercel/vercel/pull/5407
Fixes: https://github.com/vercel/next.js/issues/19324
2020-11-19 20:24:46 +00:00
luc
18c3dd3a63 Publish Canary
- vercel@20.1.5-canary.5
2020-11-19 16:01:27 +01:00
Ana Trajkovska
5a4a20b33f Remove code which removes auto-generated secrets (#5440) 2020-11-19 16:00:57 +01:00
luc
4489ed0c85 Publish Canary
- vercel@20.1.5-canary.4
2020-11-18 16:11:28 +01:00
Luc Leray
359f23daf1 [cli] Expose VERCEL_REGION when autoExposeSystemEnvs is true (#5437)
* auto expose VERCEL_REGION

* add test
2020-11-18 16:00:20 +01:00
luc
4ef92e85db Publish Canary
- vercel@20.1.5-canary.3
2020-11-18 00:27:15 +01:00
Naoyuki Kanezawa
659c4d6ccd [cli] Expose system envs when autoExposeSystemEnvs is enabled on vc dev (#5434)
Ref: https://app.clubhouse.io/vercel/story/15112

We added a property called `autoExposeSystemEnvs` to projects. If that property is `true`, we automatically expose system env variables such as `VERCEL=1`, `VERCEL_ENV=<production | preview>`, ... to the runtime and build time.

This PR makes sure we mirror this behavior when running `vc dev` locally.

### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [x] The code changed/added as part of this PR has been covered with tests
- [x] All tests pass locally with `yarn test-unit`

#### Code Review

- [x] This PR has a concise title and thorough description useful to a reviewer
- [x] Issue from task tracker has a link to this PR
2020-11-17 23:21:40 +00:00
JJ Kasper
e93d477df8 Publish Stable
- @vercel/next@2.7.2
2020-11-17 14:49:04 -06:00
JJ Kasper
f64625655b Publish Canary
- @vercel/next@2.7.2-canary.0
2020-11-17 14:11:32 -06:00
JJ Kasper
25a8189997 [next] Correct non-dynamic index SSG data route output (#5435)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-11-17 15:09:56 -05:00
Andy Bitz
25c3e627cf Publish Canary
- @vercel/build-utils@2.6.1-canary.0
 - vercel@20.1.5-canary.2
 - @vercel/client@9.0.5-canary.0
2020-11-17 18:13:30 +01:00
Andy
1d6d8b530f [build-utils] Remove continue: true from 404 route (#5432)
* [build-utils] Remove `continue: true` from 404 route

* Update tests
2020-11-17 18:08:29 +01:00
Steven
e821cc0ae7 [cli] Add tests to compare dev/prd image optimization (#5428)
Add E2E test for to test image optimization against `vc dev` as well as a prod deployment.

### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [x] The code changed/added as part of this PR has been covered with tests
- [x] All tests pass locally with `yarn test-unit`

#### Code Review

- [x] This PR has a concise title and thorough description useful to a reviewer
- [x] Issue from task tracker has a link to this PR (CH13104)
2020-11-16 20:20:27 +00:00
JJ Kasper
8ecbdc5d03 Publish Stable
- @vercel/next@2.7.1
2020-11-14 16:48:35 -06:00
JJ Kasper
895224985b Publish Canary
- @vercel/next@2.7.1-canary.0
2020-11-14 16:23:24 -06:00
JJ Kasper
0f42a63c03 [next] Ensure correct route order for i18n + custom-routes (#5421)
Co-authored-by: Steven <steven@ceriously.com>
2020-11-14 17:13:08 -05:00
dav-is
81e4c9e6fe Publish Canary
- @vercel/routing-utils@1.9.2-canary.1
2020-11-13 13:48:28 -05:00
Connor Davis
a0a29dc836 [routing-utils] Exclude /.well-known from trailing slash redirect (#5407)
`/.well-known` files shouldn't have trailing slashes added as these clients likely do not follow redirects

Specifically, `/.well-known/apple-developer-merchantid-domain-association` cannot have trailing slash.

### Related Issues

https://vercel.slack.com/archives/CLDDX2Y0G/p1605127589058800

#### Tests

- [x] The code changed/added as part of this PR has been covered with tests
- [x] All tests pass locally with `yarn test-unit`

#### Code Review

- [x] This PR has a concise title and thorough description useful to a reviewer
- [x] Issue from task tracker has a link to this PR
2020-11-12 22:38:01 +00:00
luc
c1f9d51d7a Publish Canary
- vercel@20.1.5-canary.1
2020-11-12 22:06:16 +01:00
Luc Leray
422f0558c1 [cli] Rename "Provided by system" to "Reference ..." (#5415)
* Revert "Revert "[cli] (major) Update `vercel env` (#5372)" (#5410)"

This reverts commit 2d24a75ca6.

* fetch system env values from dedicated endpoint

* rename "Provided by System"
2020-11-12 22:05:24 +01:00
luc
f064ae2908 Publish Canary
- vercel@20.1.5-canary.0
 - @vercel/routing-utils@1.9.2-canary.0
2020-11-12 21:07:28 +01:00
Luc Leray
58c3e636f0 [cli] (Major) Update vc env (#5413)
* Revert "Revert "[cli] (major) Update `vercel env` (#5372)" (#5410)"

This reverts commit 2d24a75ca6.

* fetch system env values from dedicated endpoint
2020-11-12 21:06:25 +01:00
Connor Davis
d5081367f3 [routing-utils] Add important headers to disallow users from overriding (#5409)
If a builder wants to set a header that isn't allowed to be overridden by users, it should use `important: true`

#### Tests

- [x] The code changed/added as part of this PR has been covered with tests
- [x] All tests pass locally with `yarn test-unit`

#### Code Review

- [x] This PR has a concise title and thorough description useful to a reviewer
- [x] Issue from task tracker has a link to this PR: CH-14921
2020-11-12 17:45:33 +00:00
luc
0ee88366ff Publish Stable
- vercel@20.1.4
2020-11-12 17:16:29 +01:00
luc
9ae42c9e92 Publish Canary
- vercel@20.1.4-canary.1
2020-11-12 16:59:28 +01:00
Luc Leray
62b8df4a8d [cli] Fix vc env rm with advanced env variables (#5411) 2020-11-12 16:58:41 +01:00
luc
73ec7f3018 Publish Canary
- vercel@20.1.4-canary.0
2020-11-12 15:31:54 +01:00
Luc Leray
2d24a75ca6 Revert "[cli] (major) Update vercel env (#5372)" (#5410)
* Revert "[cli] (major) Update `vercel env` (#5372)"

This reverts commit 9a57cc72dd.

* fix test

* do not change prompt UI
2020-11-12 15:30:47 +01:00
43 changed files with 750 additions and 182 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/build-utils",
"version": "2.6.0",
"version": "2.6.1-canary.0",
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.js",

View File

@@ -989,7 +989,6 @@ function getRouteResult(
rewriteRoutes.push({
src: '^/api(/.*)?$',
status: 404,
continue: true,
});
}
} else {

View File

@@ -2393,7 +2393,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
expect(errorRoutes).toStrictEqual([
@@ -2495,7 +2494,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2533,7 +2531,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2571,7 +2568,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2604,7 +2600,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2632,7 +2627,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2663,7 +2657,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2690,7 +2683,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2725,7 +2717,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
expect(errorRoutes).toStrictEqual([
@@ -2820,7 +2811,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2853,7 +2843,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2887,7 +2876,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2913,7 +2901,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2937,7 +2924,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2962,7 +2948,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -2983,7 +2968,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -3018,7 +3002,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
@@ -3076,7 +3059,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -3109,7 +3091,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -3143,7 +3124,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -3162,7 +3142,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -3186,7 +3165,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -3211,7 +3189,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}
@@ -3232,7 +3209,6 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
{
status: 404,
src: '^/api(/.*)?$',
continue: true,
},
]);
}

View File

@@ -1,6 +1,6 @@
{
"name": "vercel",
"version": "20.1.3",
"version": "20.1.5-canary.5",
"preferGlobal": true,
"license": "Apache-2.0",
"description": "The command-line interface for Vercel",
@@ -61,7 +61,7 @@
"node": ">= 10"
},
"dependencies": {
"@vercel/build-utils": "2.6.0",
"@vercel/build-utils": "2.6.1-canary.0",
"@vercel/go": "1.1.6",
"@vercel/node": "1.8.5",
"@vercel/python": "1.2.3",

View File

@@ -2,6 +2,8 @@ import { resolve, join } from 'path';
import DevServer from '../../util/dev/server';
import parseListen from '../../util/dev/parse-listen';
import exposeSystemEnvs from '../../util/dev/expose-system-envs';
import { SystemEnvs } from '../../util/dev/types';
import { Output } from '../../util/output';
import { NowContext } from '../../types';
import Client from '../../util/client';
@@ -71,6 +73,7 @@ export default async function dev(
let frameworkSlug: string | undefined;
let projectSettings: ProjectSettings | undefined;
let environmentVars: Env | undefined;
let systemEnvs: SystemEnvs | undefined;
if (link.status === 'linked') {
const { project, org } = link;
client.currentTeam = org.type === 'team' ? org.id : undefined;
@@ -98,12 +101,17 @@ export default async function dev(
cwd = join(cwd, project.rootDirectory);
}
environmentVars = await getDecryptedEnvRecords(
output,
client,
project,
ProjectEnvTarget.Development
);
[environmentVars, systemEnvs] = await Promise.all([
getDecryptedEnvRecords(
output,
client,
project,
ProjectEnvTarget.Development
),
project.autoExposeSystemEnvs
? exposeSystemEnvs(output, client, project.id)
: undefined,
]);
}
const devServer = new DevServer(cwd, {
@@ -113,6 +121,7 @@ export default async function dev(
frameworkSlug,
projectSettings,
environmentVars,
systemEnvs,
});
process.once('SIGINT', () => devServer.stop());

View File

@@ -18,7 +18,7 @@ import withSpinner from '../../util/with-spinner';
import { emoji, prependEmoji } from '../../util/emoji';
import { isKnownError } from '../../util/env/known-error';
import { getCommandName } from '../../util/pkg-name';
import { SYSTEM_ENV_VALUES } from '../../util/env/system-env';
import getSystemEnvValues from '../../util/env/get-system-env-values';
type Options = {
'--debug': boolean;
@@ -91,7 +91,10 @@ export default async function add(
name: `Secret (can be created using ${getCommandName('secret add')})`,
value: ProjectEnvType.Secret,
},
{ name: 'Provided by System', value: ProjectEnvType.System },
{
name: 'Reference to System Environment Variable',
value: ProjectEnvType.System,
},
],
})) as { inputEnvType: ProjectEnvType };
@@ -112,7 +115,10 @@ export default async function add(
}
}
const { envs } = await getEnvVariables(output, client, project.id);
const [{ envs }, { systemEnvValues }] = await Promise.all([
getEnvVariables(output, client, project.id),
getSystemEnvValues(output, client, project.id),
]);
const existing = new Set(
envs.filter(r => r.key === envName).map(r => r.target)
);
@@ -182,7 +188,7 @@ export default async function add(
name: 'systemEnvValue',
type: 'list',
message: `Whats the value of ${envName}?`,
choices: SYSTEM_ENV_VALUES.map(value => ({ name: value, value })),
choices: systemEnvValues.map(value => ({ name: value, value })),
});
envValue = systemEnvValue;

View File

@@ -243,6 +243,7 @@ export interface Project extends ProjectSettings {
framework?: string | null;
rootDirectory?: string | null;
latestDeployments?: Partial<Deployment>[];
autoExposeSystemEnvs?: boolean;
}
export interface Org {

View File

@@ -35,6 +35,7 @@ import {
BuildResultV3,
BuilderOutputs,
EnvConfigs,
SystemEnvs,
} from './types';
import { normalizeRoutes } from '@vercel/routing-utils';
import getUpdateCommand from '../get-update-command';
@@ -53,6 +54,7 @@ interface BuildMessageResult extends BuildMessage {
async function createBuildProcess(
match: BuildMatch,
envConfigs: EnvConfigs,
systemEnvs: SystemEnvs,
workPath: string,
output: Output
): Promise<ChildProcess> {
@@ -66,6 +68,7 @@ async function createBuildProcess(
const env: Env = {
...process.env,
PATH,
...systemEnvs.buildEnv,
...envConfigs.allEnv,
};
@@ -109,7 +112,13 @@ export async function executeBuild(
builderWithPkg: { runInProcess, requirePath, builder, package: pkg },
} = match;
const { entrypoint } = match;
const { debug, envConfigs, cwd: workPath, devCacheDir } = devServer;
const {
debug,
envConfigs,
systemEnvs,
cwd: workPath,
devCacheDir,
} = devServer;
const startTime = Date.now();
const showBuildTimestamp =
@@ -131,6 +140,7 @@ export async function executeBuild(
buildProcess = await createBuildProcess(
match,
envConfigs,
systemEnvs,
workPath,
devServer.output
);
@@ -149,8 +159,8 @@ export async function executeBuild(
filesRemoved,
// This env distiniction is only necessary to maintain
// backwards compatibility with the `@vercel/next` builder.
env: envConfigs.runEnv,
buildEnv: envConfigs.buildEnv,
env: { ...systemEnvs.runEnv, ...envConfigs.runEnv },
buildEnv: { ...systemEnvs.buildEnv, ...envConfigs.buildEnv },
},
};

View File

@@ -0,0 +1,27 @@
import { SystemEnvs } from './types';
import getSystemEnvValues from '../env/get-system-env-values';
import Client from '../client';
import { Output } from '../output';
export default async function exposeSystemEnvs(
output: Output,
client: Client,
projectId: string
) {
const systemEnvs: SystemEnvs = {
buildEnv: { VERCEL: '1', VERCEL_ENV: 'development' },
runEnv: { VERCEL: '1', VERCEL_ENV: 'development', VERCEL_REGION: 'dev1' },
};
const { systemEnvValues } = await getSystemEnvValues(
output,
client,
projectId
);
for (const key of systemEnvValues) {
systemEnvs.buildEnv[key] = '';
systemEnvs.runEnv[key] = '';
}
return systemEnvs;
}

View File

@@ -84,6 +84,7 @@ import {
RouteResult,
HttpHeadersConfig,
EnvConfigs,
SystemEnvs,
} from './types';
import { ProjectSettings } from '../../types';
@@ -119,6 +120,7 @@ export default class DevServer {
public output: Output;
public proxy: httpProxy;
public envConfigs: EnvConfigs;
public systemEnvs: SystemEnvs;
public frameworkSlug?: string;
public files: BuilderInputs;
public address: string;
@@ -156,6 +158,7 @@ export default class DevServer {
this.debug = options.debug;
this.output = options.output;
this.envConfigs = { buildEnv: {}, runEnv: {}, allEnv: {} };
this.systemEnvs = options.systemEnvs || { buildEnv: {}, runEnv: {} };
this.environmentVars = options.environmentVars;
this.files = {};
this.address = '';
@@ -840,6 +843,11 @@ export default class DevServer {
const nowConfig = await this.getNowConfig();
const devCommandPromise = this.runDevCommand();
this.systemEnvs.buildEnv = this.populateVercelEnvVars(
this.systemEnvs.buildEnv
);
this.systemEnvs.runEnv = this.populateVercelEnvVars(this.systemEnvs.runEnv);
const files = await getFiles(this.cwd, { output: this.output });
this.files = {};
for (const fsPath of files) {
@@ -1648,7 +1656,13 @@ export default class DevServer {
if (typeof builder.startDevServer === 'function') {
let devServerResult: StartDevServerResult = null;
try {
const { envConfigs, files, devCacheDir, cwd: workPath } = this;
const {
envConfigs,
systemEnvs,
files,
devCacheDir,
cwd: workPath,
} = this;
devServerResult = await builder.startDevServer({
files,
entrypoint: match.entrypoint,
@@ -1658,8 +1672,8 @@ export default class DevServer {
isDev: true,
requestPath,
devCacheDir,
env: envConfigs.runEnv,
buildEnv: envConfigs.buildEnv,
env: { ...systemEnvs.runEnv, ...envConfigs.runEnv },
buildEnv: { ...systemEnvs.buildEnv, ...envConfigs.buildEnv },
},
});
} catch (err) {
@@ -1998,6 +2012,7 @@ export default class DevServer {
FORCE_COLOR: process.stdout.isTTY ? '1' : '0',
...(this.frameworkSlug === 'create-react-app' ? { BROWSER: 'none' } : {}),
...process.env,
...this.systemEnvs.buildEnv,
...this.envConfigs.allEnv,
PORT: `${port}`,
};

View File

@@ -28,6 +28,7 @@ export interface DevServerOptions {
frameworkSlug?: string;
projectSettings?: ProjectSettings;
environmentVars?: Env;
systemEnvs?: SystemEnvs;
}
export interface EnvConfigs {
@@ -47,6 +48,11 @@ export interface EnvConfigs {
allEnv: Env;
}
export interface SystemEnvs {
buildEnv: Env;
runEnv: Env;
}
export interface BuildMatch extends BuildConfig {
entrypoint: string;
builderWithPkg: BuilderWithPackage;

View File

@@ -0,0 +1,12 @@
import { Output } from '../output';
import Client from '../client';
export default async function getSystemEnvValues(
output: Output,
client: Client,
projectId: string
) {
output.debug(`Fetching System Environment Values of project ${projectId}`);
const url = `/v6/projects/${projectId}/system-env-values`;
return client.fetch<{ systemEnvValues: string[] }>(url);
}

View File

@@ -1,6 +1,6 @@
import { Output } from '../output';
import Client from '../client';
import { ProjectEnvTarget, Secret, ProjectEnvVariableV5 } from '../../types';
import { ProjectEnvTarget, ProjectEnvVariableV5 } from '../../types';
export default async function removeEnvRecord(
output: Output,
@@ -18,32 +18,7 @@ export default async function removeEnvRecord(
envName
)}${qs}`;
const env = await client.fetch<ProjectEnvVariableV5>(urlProject, {
await client.fetch<ProjectEnvVariableV5>(urlProject, {
method: 'DELETE',
});
if (env && env.value) {
const idOrName = env.value.startsWith('@') ? env.value.slice(1) : env.value;
const urlSecret = `/v2/now/secrets/${idOrName}`;
let secret: Secret | undefined;
try {
secret = await client.fetch<Secret>(urlSecret);
} catch (error) {
if (error && error.status === 404) {
// User likely deleted the secret before the env var, so we can still report success
output.debug(
`Skipped ${env.key} because secret ${idOrName} was already deleted`
);
return;
}
throw error;
}
// Since integrations add global secrets, we must only delete if the secret was
// specifically added to this project
if (secret && secret.projectId === projectId) {
await client.fetch<Secret>(urlSecret, { method: 'DELETE' });
}
}
}

View File

@@ -1,32 +0,0 @@
export const SYSTEM_ENV_VALUES = [
'VERCEL_URL',
'VERCEL_GITHUB_COMMIT_ORG',
'VERCEL_GITHUB_COMMIT_REF',
'VERCEL_GITHUB_ORG',
'VERCEL_GITHUB_DEPLOYMENT',
'VERCEL_GITHUB_COMMIT_REPO',
'VERCEL_GITHUB_REPO',
'VERCEL_GITHUB_COMMIT_AUTHOR_LOGIN',
'VERCEL_GITHUB_COMMIT_AUTHOR_NAME',
'VERCEL_GITHUB_COMMIT_SHA',
'VERCEL_GITLAB_DEPLOYMENT',
'VERCEL_GITLAB_PROJECT_NAMESPACE',
'VERCEL_GITLAB_PROJECT_NAME',
'VERCEL_GITLAB_PROJECT_ID',
'VERCEL_GITLAB_PROJECT_PATH',
'VERCEL_GITLAB_COMMIT_REF',
'VERCEL_GITLAB_COMMIT_SHA',
'VERCEL_GITLAB_COMMIT_MESSAGE',
'VERCEL_GITLAB_COMMIT_AUTHOR_LOGIN',
'VERCEL_GITLAB_COMMIT_AUTHOR_NAME',
'VERCEL_BITBUCKET_DEPLOYMENT',
'VERCEL_BITBUCKET_REPO_OWNER',
'VERCEL_BITBUCKET_REPO_SLUG',
'VERCEL_BITBUCKET_REPO_NAME',
'VERCEL_BITBUCKET_COMMIT_REF',
'VERCEL_BITBUCKET_COMMIT_SHA',
'VERCEL_BITBUCKET_COMMIT_MESSAGE',
'VERCEL_BITBUCKET_COMMIT_AUTHOR_NAME',
'VERCEL_BITBUCKET_COMMIT_AUTHOR_URL',
'VERCEL_BITBUCKET_COMMIT_AUTHOR_AVATAR',
];

View File

@@ -0,0 +1,4 @@
.next
!public
yarn.lock
.vercel

View File

@@ -0,0 +1,12 @@
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build"
},
"dependencies": {
"next": "canary",
"react": "^17.0.0",
"react-dom": "^17.0.0"
}
}

View File

@@ -0,0 +1,15 @@
import Image from 'next/image';
export default function Home() {
return (
<>
<h1>Home Page</h1>
<hr />
<h2>Optimized</h2>
<Image src="/test.png" width="400" height="400" />
<hr />
<h2>Original</h2>
<img src="/test.png" width="400" height="400" />
</>
);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="400.000000pt" height="400.000000pt" viewBox="0 0 400.000000 400.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,400.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M0 2000 l0 -2000 2000 0 2000 0 0 2000 0 2000 -2000 0 -2000 0 0
-2000z m2401 118 l396 -693 -398 -3 c-220 -1 -578 -1 -798 0 l-398 3 396 693
c217 380 398 692 401 692 3 0 184 -312 401 -692z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 635 B

View File

@@ -0,0 +1,8 @@
{
"version": 2,
"build": {
"env": {
"FORCE_BUILDER_TAG": "canary"
}
}
}

View File

@@ -128,14 +128,13 @@ async function testPath(
status,
path,
expectedText,
headers = {},
method = 'GET',
body = undefined
expectedHeaders = {},
fetchOpts = {}
) {
const opts = { redirect: 'manual-dont-change', method, body };
const opts = { ...fetchOpts, redirect: 'manual-dont-change' };
const url = `${origin}${path}`;
const res = await fetch(url, opts);
const msg = `Testing response from ${method} ${url}`;
const msg = `Testing response from ${fetchOpts.method || 'GET'} ${url}`;
console.log(msg);
t.is(res.status, status, msg);
validateResponseHeaders(t, res);
@@ -150,8 +149,8 @@ async function testPath(
expectedText.lastIndex = 0; // reset since we test twice
t.regex(actualText, expectedText);
}
if (headers) {
Object.entries(headers).forEach(([key, expectedValue]) => {
if (expectedHeaders) {
Object.entries(expectedHeaders).forEach(([key, expectedValue]) => {
let actualValue = res.headers.get(key);
if (key.toLowerCase() === 'location' && actualValue === '//') {
// HACK: `node-fetch` has strange behavior for location header so fix it
@@ -387,9 +386,12 @@ test(
async testPath => {
await testPath(200, '/', /<div id="redwood-app">/m);
await testPath(200, '/about', /<div id="redwood-app">/m);
const reqBody = '{"query":"{redwood{version}}"}';
const fetchOpts = {
method: 'POST',
body: '{"query":"{redwood{version}}"}',
};
const resBody = '{"data":{"redwood":{"version":"0.15.0"}}}';
await testPath(200, '/api/graphql', resBody, {}, 'POST', reqBody);
await testPath(200, '/api/graphql', resBody, {}, fetchOpts);
},
{ isExample: true }
)
@@ -945,12 +947,16 @@ test(
'Access-Control-Allow-Methods':
'GET, POST, OPTIONS, HEAD, PATCH, PUT, DELETE',
};
await testPath(200, '/', 'status api', headers, 'GET');
await testPath(200, '/', 'status api', headers, 'POST');
await testPath(200, '/api/status.js', 'status api', headers, 'GET');
await testPath(200, '/api/status.js', 'status api', headers, 'POST');
await testPath(204, '/', '', headers, 'OPTIONS');
await testPath(204, '/api/status.js', '', headers, 'OPTIONS');
await testPath(200, '/', 'status api', headers, { method: 'GET' });
await testPath(200, '/', 'status api', headers, { method: 'POST' });
await testPath(200, '/api/status.js', 'status api', headers, {
method: 'GET',
});
await testPath(200, '/api/status.js', 'status api', headers, {
method: 'POST',
});
await testPath(204, '/', '', headers, { method: 'OPTIONS' });
await testPath(204, '/api/status.js', '', headers, { method: 'OPTIONS' });
})
);
@@ -1595,6 +1601,61 @@ test(
})
);
test(
'[vercel dev] 30-next-image-optimization',
testFixtureStdio('30-next-image-optimization', async testPath => {
const toUrl = (url, w, q) => {
const query = new URLSearchParams();
query.append('url', url);
query.append('w', w);
query.append('q', q);
return `/_next/image?${query}`;
};
const expectHeader = accept => ({
'content-type': accept,
'cache-control': 'public, max-age=0, must-revalidate',
});
const fetchOpts = accept => ({ method: 'GET', headers: { accept } });
await testPath(200, '/', /Home Page/m);
await testPath(
200,
toUrl('/test.jpg', 64, 100),
null,
expectHeader('image/webp'),
fetchOpts('image/webp')
);
await testPath(
200,
toUrl('/test.png', 64, 90),
null,
expectHeader('image/webp'),
fetchOpts('image/webp')
);
await testPath(
200,
toUrl('/test.gif', 64, 80),
null,
expectHeader('image/webp'),
fetchOpts('image/webp')
);
await testPath(
200,
toUrl('/test.svg', 64, 70),
null,
expectHeader('image/svg+xml'),
fetchOpts('image/webp')
);
await testPath(
200,
toUrl('/animated.gif', 64, 60),
null,
expectHeader('image/gif'),
fetchOpts('image/gif')
);
})
);
test(
'[vercel dev] Use `@vercel/python` with Flask requirements.txt',
testFixtureStdio('python-flask', async testPath => {

View File

@@ -762,6 +762,70 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
t.is(homeJson['VERCEL_URL'], localhostNoProtocol);
t.is(homeJson['MY_STDIN_VAR'], '{"expect":"quotes"}');
// system env vars are not automatically exposed
t.is(apiJson['VERCEL'], undefined);
t.is(homeJson['VERCEL'], undefined);
vc.kill('SIGTERM', { forceKillAfterTimeout: 2000 });
const { exitCode, stderr, stdout } = await vc;
t.is(exitCode, 0, formatOutput({ stderr, stdout }));
}
async function enableAutoExposeSystemEnvs() {
const link = require(path.join(target, '.vercel/project.json'));
const res = await apiFetch(`/v2/projects/${link.projectId}`, {
method: 'PATCH',
body: JSON.stringify({ autoExposeSystemEnvs: true }),
});
t.is(res.status, 200);
if (res.status === 200) {
console.log(
`Set autoExposeSystemEnvs=true for project ${link.projectId}`
);
}
}
async function nowDevAndFetchSystemVars() {
const vc = execa(binaryPath, ['dev', ...defaultArgs], {
reject: false,
cwd: target,
});
let localhost = undefined;
await waitForPrompt(vc, chunk => {
if (chunk.includes('Ready! Available at')) {
localhost = /(https?:[^\s]+)/g.exec(chunk);
return true;
}
return false;
});
const apiUrl = `${localhost[0]}/api/get-env`;
const apiRes = await fetch(apiUrl);
const localhostNoProtocol = localhost[0].slice('http://'.length);
const apiJson = await apiRes.json();
t.is(apiJson['VERCEL'], '1');
t.is(apiJson['VERCEL_URL'], localhostNoProtocol);
t.is(apiJson['VERCEL_ENV'], 'development');
t.is(apiJson['VERCEL_REGION'], 'dev1');
t.is(apiJson['VERCEL_GIT_PROVIDER'], '');
t.is(apiJson['VERCEL_GIT_REPO_SLUG'], '');
const homeUrl = localhost[0];
const homeRes = await fetch(homeUrl);
const homeJson = await homeRes.json();
t.is(homeJson['VERCEL'], '1');
t.is(homeJson['VERCEL_URL'], localhostNoProtocol);
t.is(homeJson['VERCEL_ENV'], 'development');
t.is(homeJson['VERCEL_REGION'], undefined);
t.is(homeJson['VERCEL_GIT_PROVIDER'], '');
t.is(homeJson['VERCEL_GIT_REPO_SLUG'], '');
vc.kill('SIGTERM', { forceKillAfterTimeout: 2000 });
const { exitCode, stderr, stdout } = await vc;
@@ -869,6 +933,8 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
await nowDevWithEnv();
fs.unlinkSync(path.join(target, '.env'));
await nowDevAndFetchCloudVars();
await enableAutoExposeSystemEnvs();
await nowDevAndFetchSystemVars();
await nowEnvRemove();
await nowEnvRemoveWithArgs();
await nowEnvRemoveWithNameOnly();

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/client",
"version": "9.0.4",
"version": "9.0.5-canary.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"homepage": "https://vercel.com",
@@ -37,7 +37,7 @@
]
},
"dependencies": {
"@vercel/build-utils": "2.6.0",
"@vercel/build-utils": "2.6.1-canary.0",
"@zeit/fetch": "5.2.0",
"async-retry": "1.2.3",
"async-sema": "3.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/next",
"version": "2.7.0",
"version": "2.7.3-canary.0",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",

View File

@@ -448,7 +448,7 @@ export async function build({
const prerenderManifest = await getPrerenderManifest(entryPath);
const headers: Route[] = [];
const rewrites: Route[] = [];
const redirects: Route[] = [];
let redirects: Route[] = [];
const dataRoutes: Route[] = [];
let dynamicRoutes: Route[] = [];
// whether they have enabled pages/404.js as the custom 404 page
@@ -1769,12 +1769,7 @@ export async function build({
if (nonDynamicSsg || isFallback) {
outputPathData = outputPathData.replace(
new RegExp(`${escapeStringRegexp(origRouteFileNoExt)}.json$`),
`${routeFileNoExt}${
routeFileNoExt !== origRouteFileNoExt &&
origRouteFileNoExt === '/index'
? '/index'
: ''
}.json`
`${routeFileNoExt}.json`
);
}
@@ -2020,6 +2015,33 @@ export async function build({
const { i18n } = routesManifest || {};
const trailingSlashRedirects: Route[] = [];
let trailingSlash = false;
redirects = redirects.filter(_redir => {
const redir = _redir as Source;
// detect the trailing slash redirect and make sure it's
// kept above the wildcard mapping to prevent erroneous redirects
// since non-continue routes come after continue the $wildcard
// route will come before the redirect otherwise and if the
// redirect is triggered it breaks locale mapping
const location =
redir.headers && (redir.headers.location || redir.headers.Location);
if (redir.status === 308 && (location === '/$1' || location === '/$1/')) {
// we set continue here to prevent the redirect from
// moving underneath i18n routes
if (location === '/$1/') {
trailingSlash = true;
}
redir.continue = true;
trailingSlashRedirects.push(redir);
return false;
}
return true;
});
return {
output: {
...publicDirectoryFiles,
@@ -2059,36 +2081,22 @@ export async function build({
- Builder rewrites
*/
routes: [
// headers
...headers,
// redirects
...redirects.map(_redir => {
if (i18n) {
const redir = _redir as Source;
// detect the trailing slash redirect and make sure it's
// kept above the wildcard mapping to prevent erroneous redirects
// since non-continue routes come after continue the $wildcard
// route will come before the redirect otherwise and if the
// redirect is triggered it breaks locale mapping
const location =
redir.headers && (redir.headers.location || redir.headers.Location);
if (
redir.status === 308 &&
(location === '/$1' || location === '/$1/')
) {
// we set continue true
redir.continue = true;
}
}
return _redir;
}),
...(trailingSlash
? [
{
src: '^/\\.well-known(?:/.*)?$',
},
]
: []),
// force trailingSlashRedirect to the very top so it doesn't
// conflict with i18n routes that don't have or don't have the
// trailing slash
...trailingSlashRedirects,
...(i18n
? [
// Handle auto-adding current default locale to path based on $wildcard
// Handle auto-adding current default locale to path based on
// $wildcard
{
src: `^${path.join(
'/',
@@ -2097,8 +2105,8 @@ export async function build({
)}(?!(?:_next/.*|${i18n.locales
.map(locale => escapeStringRegexp(locale))
.join('|')})(?:/.*|$))(.*)$`,
// TODO: this needs to contain or not contain a trailing slash
// to prevent the trailing slash redirect from being triggered
// we aren't able to ensure trailing slash mode here
// so ensure this comes after the trailing slash redirect
dest: '$wildcard/$1',
continue: true,
},
@@ -2107,8 +2115,6 @@ export async function build({
...(i18n.domains && i18n.localeDetection !== false
? [
{
// TODO: enable redirecting between domains, will require
// updating the src with the desired locales to redirect
src: `^${path.join(
'/',
entryDirectory
@@ -2144,10 +2150,10 @@ export async function build({
...(i18n.localeDetection !== false
? [
{
// TODO: if default locale is included in this src it won't be
// visitable by users who prefer another language since a
// cookie isn't set signaling the default locale is preferred
// on redirect currently, investigate adding this
// TODO: if default locale is included in this src it won't
// be visitable by users who prefer another language since a
// cookie isn't set signaling the default locale is
// preferred on redirect currently, investigate adding this
src: '/',
locale: {
redirect: i18n.locales.reduce(
@@ -2190,6 +2196,12 @@ export async function build({
]
: []),
// headers
...headers,
// redirects
...redirects,
// Make sure to 404 for the /404 path itself
...(i18n
? [
@@ -2253,16 +2265,16 @@ export async function build({
dest: '$0',
},
// remove default locale prefix to check public files
// remove locale prefixes to check public files
...(i18n
? [
{
src: `${path.join(
src: `^${path.join(
'/',
entryDirectory,
i18n.defaultLocale,
'/'
)}(.*)`,
entryDirectory
)}/?(?:${i18n.locales
.map(locale => escapeStringRegexp(locale))
.join('|')})/(.*)`,
dest: `${path.join('/', entryDirectory, '/')}$1`,
check: true,
},

View File

@@ -427,22 +427,22 @@
},
{
"path": "/_next/data/testing-build-id/en-US/index.json",
"path": "/_next/data/testing-build-id/en-US.json",
"status": 200,
"mustContain": "\"locale\":\"en-US\""
},
{
"path": "/_next/data/testing-build-id/en/index.json",
"path": "/_next/data/testing-build-id/en.json",
"status": 200,
"mustContain": "\"locale\":\"en\""
},
{
"path": "/_next/data/testing-build-id/fr/index.json",
"path": "/_next/data/testing-build-id/fr.json",
"status": 200,
"mustContain": "\"locale\":\"fr\""
},
{
"path": "/_next/data/testing-build-id/nl/index.json",
"path": "/_next/data/testing-build-id/nl.json",
"status": 200,
"mustContain": "\"locale\":\"nl\""
},

View File

@@ -5,7 +5,7 @@ const cheerio = require('cheerio');
module.exports = function (ctx) {
it('should revalidate content properly from /', async () => {
const dataRes = await fetch(
`${ctx.deploymentUrl}/_next/data/testing-build-id/en-US/index.json`
`${ctx.deploymentUrl}/_next/data/testing-build-id/en-US.json`
);
expect(dataRes.status).toBe(200);
await dataRes.json();
@@ -36,7 +36,7 @@ module.exports = function (ctx) {
it('should revalidate content properly from /fr', async () => {
const dataRes = await fetch(
`${ctx.deploymentUrl}/_next/data/testing-build-id/fr/index.json`
`${ctx.deploymentUrl}/_next/data/testing-build-id/fr.json`
);
expect(dataRes.status).toBe(200);
await dataRes.json();
@@ -67,7 +67,7 @@ module.exports = function (ctx) {
it('should revalidate content properly from /nl-NL', async () => {
const dataRes = await fetch(
`${ctx.deploymentUrl}/_next/data/testing-build-id/nl-NL/index.json`
`${ctx.deploymentUrl}/_next/data/testing-build-id/nl-NL.json`
);
expect(dataRes.status).toBe(200);
await dataRes.json();

View File

@@ -18,4 +18,81 @@ module.exports = {
},
],
},
async redirects() {
return [
{
source: '/en-US/redirect-1',
destination: '/somewhere-else',
permanent: false,
locale: false,
},
{
source: '/nl/redirect-2',
destination: '/somewhere-else',
permanent: false,
locale: false,
},
{
source: '/redirect-3',
destination: '/somewhere-else',
permanent: false,
},
];
},
async rewrites() {
return [
{
source: '/en-US/rewrite-1',
destination: '/another',
locale: false,
},
{
source: '/nl/rewrite-2',
destination: '/nl/another',
locale: false,
},
{
source: '/fr/rewrite-3',
destination: '/nl/another',
locale: false,
},
{
source: '/rewrite-4',
destination: '/another',
},
];
},
async headers() {
return [
{
source: '/en-US/add-header-1',
locale: false,
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
{
source: '/nl/add-header-2',
locale: false,
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
{
source: '/add-header-3',
headers: [
{
key: 'x-hello',
value: 'world',
},
],
},
];
},
};

View File

@@ -435,22 +435,22 @@
},
{
"path": "/_next/data/testing-build-id/en-US/index.json",
"path": "/_next/data/testing-build-id/en-US.json",
"status": 200,
"mustContain": "\"locale\":\"en-US\""
},
{
"path": "/_next/data/testing-build-id/en/index.json",
"path": "/_next/data/testing-build-id/en.json",
"status": 200,
"mustContain": "\"locale\":\"en\""
},
{
"path": "/_next/data/testing-build-id/fr/index.json",
"path": "/_next/data/testing-build-id/fr.json",
"status": 200,
"mustContain": "\"locale\":\"fr\""
},
{
"path": "/_next/data/testing-build-id/nl/index.json",
"path": "/_next/data/testing-build-id/nl.json",
"status": 200,
"mustContain": "\"locale\":\"nl\""
},
@@ -520,6 +520,280 @@
"path": "/_next/data/testing-build-id/fr/gsp/blocking/first.json",
"status": 200,
"mustContain": "\"catchall\":\"yes\""
},
{
"path": "/en-US/redirect-1",
"fetchOptions": {
"redirect": "manual"
},
"status": 307,
"responseHeaders": {
"location": "//somewhere-else/"
}
},
{
"path": "/en/redirect-1",
"fetchOptions": {
"redirect": "manual"
},
"status": 404
},
{
"path": "/nl/redirect-2",
"fetchOptions": {
"redirect": "manual"
},
"status": 307,
"responseHeaders": {
"location": "//somewhere-else/"
}
},
{
"path": "/en-US/redirect-2",
"fetchOptions": {
"redirect": "manual"
},
"status": 404
},
{
"path": "/redirect-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 307,
"responseHeaders": {
"location": "//somewhere-else/"
}
},
{
"path": "/en-US/redirect-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 307,
"responseHeaders": {
"location": "//somewhere-else/"
}
},
{
"path": "/fr/redirect-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 307,
"responseHeaders": {
"location": "//somewhere-else/"
}
},
{
"path": "/nl-NL/redirect-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 307,
"responseHeaders": {
"location": "//somewhere-else/"
}
},
{
"path": "/en-US/rewrite-1",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "another page"
},
{
"path": "/en-US/rewrite-1",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "lang=\"en-US\""
},
{
"path": "/nl/rewrite-1",
"fetchOptions": {
"redirect": "manual"
},
"status": 404
},
{
"path": "/nl/rewrite-2",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "another page"
},
{
"path": "/nl/rewrite-2",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "lang=\"nl\""
},
{
"path": "/rewrite-2",
"fetchOptions": {
"redirect": "manual"
},
"status": 404
},
{
"path": "/fr/rewrite-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "another page"
},
{
"path": "/fr/rewrite-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "lang=\"nl\""
},
{
"path": "/rewrite-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 404
},
{
"path": "/rewrite-4",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "another page"
},
{
"path": "/rewrite-4",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "lang=\"en-US\""
},
{
"path": "/en/rewrite-4",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "another page"
},
{
"path": "/en/rewrite-4",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "lang=\"en\""
},
{
"path": "/fr/rewrite-4",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "another page"
},
{
"path": "/fr/rewrite-4",
"fetchOptions": {
"redirect": "manual"
},
"status": 200,
"mustContain": "lang=\"fr\""
},
{
"path": "/en-US/add-header-1",
"fetchOptions": {
"redirect": "manual"
},
"status": 404,
"responseHeaders": {
"x-hello": "world"
}
},
{
"path": "/en/add-header-1",
"fetchOptions": {
"redirect": "manual"
},
"status": 404,
"responseHeaders": {
"x-hello": null
}
},
{
"path": "/nl/add-header-2",
"fetchOptions": {
"redirect": "manual"
},
"status": 404,
"responseHeaders": {
"x-hello": "world"
}
},
{
"path": "/en-US/add-header-2",
"fetchOptions": {
"redirect": "manual"
},
"status": 404,
"responseHeaders": {
"x-hello": null
}
},
{
"path": "/add-header-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 404,
"responseHeaders": {
"x-hello": "world"
}
},
{
"path": "/en-US/add-header-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 404,
"responseHeaders": {
"x-hello": "world"
}
},
{
"path": "/fr/add-header-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 404,
"responseHeaders": {
"x-hello": "world"
}
},
{
"path": "/nl-NL/add-header-3",
"fetchOptions": {
"redirect": "manual"
},
"status": 404,
"responseHeaders": {
"x-hello": "world"
}
}
]
}

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/routing-utils",
"version": "1.9.1",
"version": "1.9.2-canary.1",
"description": "Vercel routing utilities",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",

View File

@@ -80,6 +80,9 @@ export const routesSchema = {
check: {
type: 'boolean',
},
important: {
type: 'boolean',
},
status: {
type: 'integer',
minimum: 100,

View File

@@ -119,6 +119,9 @@ export function convertHeaders(headers: NowHeader[]): Route[] {
export function convertTrailingSlash(enable: boolean, status = 308): Route[] {
const routes: Route[] = [];
if (enable) {
routes.push({
src: '^/\\.well-known(?:/.*)?$'
});
routes.push({
src: '^/((?:[^/]+/)*[^/\\.]+)$',
headers: { Location: '/$1/' },

View File

@@ -72,6 +72,7 @@ describe('normalizeRoutes', () => {
src: '^/missed-me$',
headers: { 'Cache-Control': 'max-age=10' },
continue: true,
important: true,
},
{ handle: 'rewrite' },
{ src: '^.*$', dest: '/somewhere' },

View File

@@ -671,6 +671,7 @@ test('convertHeaders', () => {
test('convertTrailingSlash enabled', () => {
const actual = convertTrailingSlash(true);
const expected = [
{ src: '^/\\.well-known(?:/.*)?$' },
{
src: '^/((?:[^/]+/)*[^/\\.]+)$',
headers: { Location: '/$1/' },
@@ -685,11 +686,23 @@ test('convertTrailingSlash enabled', () => {
deepEqual(actual, expected);
const mustMatch = [
[
'/.well-known',
'/.well-known/',
'/.well-known/asdf',
'/.well-known/asdf/',
],
['/dir', '/dir/foo', '/dir/foo/bar'],
['/foo.html/', '/dir/foo.html/', '/dir/foo/bar.css/', '/dir/about.map.js/'],
];
const mustNotMatch = [
[
'/swell-known',
'/swell-known/',
'/swell-known/asdf',
'/swell-known/asdf/',
],
[
'/',
'/index.html',

View File

@@ -251,7 +251,9 @@ async function testDeployment(
const expected = probe.responseHeaders[header];
const isEqual = Array.isArray(expected)
? expected.every(h => actual.includes(h))
: expected.startsWith('/') && expected.endsWith('/')
: typeof expected === 'string' &&
expected.startsWith('/') &&
expected.endsWith('/')
? new RegExp(expected.slice(1, -1)).test(actual)
: expected === actual;
if (!isEqual) {