mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 12:57:46 +00:00
[next] Add @vercel/next Builder (#7793)
This commit is contained in:
@@ -19,6 +19,10 @@ packages/cli/src/util/dev/templates/*.ts
|
||||
packages/client/tests/fixtures
|
||||
packages/client/lib
|
||||
|
||||
# next
|
||||
packages/next/test/integration/middleware
|
||||
packages/next/test/integration/middleware-eval
|
||||
|
||||
# node-bridge
|
||||
packages/node-bridge/bridge.js
|
||||
packages/node-bridge/launcher.js
|
||||
|
||||
2
packages/next/.gitignore
vendored
Normal file
2
packages/next/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/dist
|
||||
test/builder-info.json
|
||||
36
packages/next/build.js
Normal file
36
packages/next/build.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const execa = require('execa');
|
||||
const { remove, rename } = require('fs-extra');
|
||||
const buildEdgeFunctionTemplate = require('./scripts/build-edge-function-template');
|
||||
|
||||
async function main() {
|
||||
const isDevBuild = process.argv.includes('--dev');
|
||||
|
||||
await remove('dist');
|
||||
await execa('tsc', [], { stdio: 'inherit' });
|
||||
await buildEdgeFunctionTemplate();
|
||||
|
||||
if (!isDevBuild) {
|
||||
await execa(
|
||||
'ncc',
|
||||
[
|
||||
'build',
|
||||
'src/index.ts',
|
||||
'--minify',
|
||||
'-e',
|
||||
'esbuild',
|
||||
'-e',
|
||||
'@vercel/build-utils',
|
||||
'-o',
|
||||
'dist/main',
|
||||
],
|
||||
{ stdio: 'inherit' }
|
||||
);
|
||||
await rename('dist/main/index.js', 'dist/index.js');
|
||||
await remove('dist/main');
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
73
packages/next/package.json
Normal file
73
packages/next/package.json
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"name": "@vercel/next",
|
||||
"version": "2.8.65",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
|
||||
"scripts": {
|
||||
"build": "node build.js",
|
||||
"build-dev": "node build.js --dev",
|
||||
"test": "jest --env node --verbose --bail --runInBand",
|
||||
"test-unit": "yarn test test/build.test.ts test/unit/",
|
||||
"test-next-local": "jest --env node --verbose --bail --forceExit --testTimeout=360000 test/integration/*.test.js test/integration/*.test.ts",
|
||||
"test-next-local:middleware": "jest --env node --verbose --bail --useStderr --testTimeout=360000 test/integration/middleware.test.ts",
|
||||
"test-integration-once": "rm test/builder-info.json; jest --env node --verbose --runInBand --bail test/fixtures/**/*.test.js",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/vercel/vercel.git",
|
||||
"directory": "packages/next"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"jest": {
|
||||
"preset": "ts-jest/presets/default",
|
||||
"testEnvironment": "node",
|
||||
"globals": {
|
||||
"ts-jest": {
|
||||
"diagnostics": true,
|
||||
"isolatedModules": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/aws-lambda": "8.10.19",
|
||||
"@types/buffer-crc32": "0.2.0",
|
||||
"@types/convert-source-map": "1.5.2",
|
||||
"@types/find-up": "4.0.0",
|
||||
"@types/fs-extra": "8.0.0",
|
||||
"@types/glob": "7.1.3",
|
||||
"@types/next-server": "8.0.0",
|
||||
"@types/node": "14.17.27",
|
||||
"@types/resolve-from": "5.0.1",
|
||||
"@types/semver": "6.0.0",
|
||||
"@types/text-table": "0.2.1",
|
||||
"@types/webpack-sources": "3.2.0",
|
||||
"@vercel/build-utils": "3.0.1",
|
||||
"@vercel/nft": "0.18.1",
|
||||
"@vercel/routing-utils": "1.13.2",
|
||||
"async-sema": "3.0.1",
|
||||
"buffer-crc32": "0.2.13",
|
||||
"cheerio": "1.0.0-rc.10",
|
||||
"convert-source-map": "1.8.0",
|
||||
"esbuild": "0.12.22",
|
||||
"escape-string-regexp": "2.0.0",
|
||||
"execa": "2.0.4",
|
||||
"find-up": "4.1.0",
|
||||
"fs-extra": "7.0.0",
|
||||
"get-port": "5.0.0",
|
||||
"nanoid": "3.3.4",
|
||||
"ndjson": "2.0.0",
|
||||
"pretty-bytes": "5.6.0",
|
||||
"resolve-from": "5.0.0",
|
||||
"semver": "6.1.1",
|
||||
"set-cookie-parser": "2.4.6",
|
||||
"source-map": "0.7.3",
|
||||
"test-listen": "1.1.0",
|
||||
"text-table": "0.2.0",
|
||||
"typescript": "4.5.2",
|
||||
"webpack-sources": "3.2.3"
|
||||
}
|
||||
}
|
||||
46
packages/next/scripts/build-edge-function-template.js
Normal file
46
packages/next/scripts/build-edge-function-template.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const { build } = require('esbuild');
|
||||
const assert = require('assert');
|
||||
const { outputFile } = require('fs-extra');
|
||||
|
||||
/**
|
||||
* @param {Pick<import('esbuild').BuildOptions, 'outfile' | 'format' | 'entryPoints' | 'write'>} options
|
||||
*/
|
||||
async function buildTemplate(options) {
|
||||
return build({
|
||||
bundle: true,
|
||||
entryPoints: options.entryPoints,
|
||||
format: options.format,
|
||||
legalComments: 'none',
|
||||
minify: process.env.NODE_ENV !== 'test',
|
||||
outfile: options.outfile,
|
||||
// Cloudflare Workers uses the V8 JavaScript engine from Google Chrome.
|
||||
// The Workers runtime is updated at least once a week, to at least the version
|
||||
// that is currently used by Chrome's stable release.
|
||||
// To see the latest stable chrome version: https://www.chromestatus.com/features/schedule
|
||||
target: 'esnext',
|
||||
write: options.write,
|
||||
});
|
||||
}
|
||||
|
||||
async function buildNextjsWrapper() {
|
||||
const { outputFiles } = await buildTemplate({
|
||||
entryPoints: ['./src/edge-function-source/get-edge-function'],
|
||||
outfile: 'dist/___get-nextjs-edge-function.js',
|
||||
format: 'cjs', // https://esbuild.github.io/api/#format
|
||||
write: false,
|
||||
});
|
||||
|
||||
assert(outputFiles);
|
||||
const [src] = outputFiles;
|
||||
|
||||
return outputFile(src.path, `module.exports = ${JSON.stringify(src.text)}`);
|
||||
}
|
||||
|
||||
module.exports = buildNextjsWrapper;
|
||||
|
||||
if (!module.parent) {
|
||||
buildNextjsWrapper().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
95
packages/next/src/create-serverless-config.ts
Normal file
95
packages/next/src/create-serverless-config.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import semver from 'semver';
|
||||
|
||||
import { ExperimentalTraceVersion } from './utils';
|
||||
|
||||
function getCustomData(importName: string, target: string) {
|
||||
return `
|
||||
// @ts-nocheck
|
||||
module.exports = function(...args) {
|
||||
let original = require('./${importName}');
|
||||
|
||||
const finalConfig = {};
|
||||
const target = { target: '${target}' };
|
||||
|
||||
if (typeof original === 'function' && original.constructor.name === 'AsyncFunction') {
|
||||
// AsyncFunctions will become promises
|
||||
original = original(...args);
|
||||
}
|
||||
|
||||
if (original instanceof Promise) {
|
||||
// Special case for promises, as it's currently not supported
|
||||
// and will just error later on
|
||||
return original
|
||||
.then((orignalConfig) => Object.assign(finalConfig, orignalConfig))
|
||||
.then((config) => Object.assign(config, target));
|
||||
} else if (typeof original === 'function') {
|
||||
Object.assign(finalConfig, original(...args));
|
||||
} else if (typeof original === 'object') {
|
||||
Object.assign(finalConfig, original);
|
||||
}
|
||||
|
||||
Object.assign(finalConfig, target);
|
||||
|
||||
return finalConfig;
|
||||
}
|
||||
`.trim();
|
||||
}
|
||||
|
||||
function getDefaultData(target: string) {
|
||||
return `
|
||||
// @ts-nocheck
|
||||
module.exports = { target: '${target}' };
|
||||
`.trim();
|
||||
}
|
||||
|
||||
export default async function createServerlessConfig(
|
||||
workPath: string,
|
||||
entryPath: string,
|
||||
nextVersion: string | undefined
|
||||
) {
|
||||
let target = 'serverless';
|
||||
|
||||
if (nextVersion) {
|
||||
try {
|
||||
if (semver.gte(nextVersion, ExperimentalTraceVersion)) {
|
||||
target = 'experimental-serverless-trace';
|
||||
}
|
||||
} catch (
|
||||
_ignored
|
||||
// eslint-disable-next-line
|
||||
) {}
|
||||
}
|
||||
const primaryConfigPath = path.join(entryPath, 'next.config.js');
|
||||
const secondaryConfigPath = path.join(workPath, 'next.config.js');
|
||||
const backupConfigName = `next.config.__vercel_builder_backup__.js`;
|
||||
|
||||
const hasPrimaryConfig = fs.existsSync(primaryConfigPath);
|
||||
const hasSecondaryConfig = fs.existsSync(secondaryConfigPath);
|
||||
|
||||
let configPath: string;
|
||||
let backupConfigPath: string;
|
||||
|
||||
if (hasPrimaryConfig) {
|
||||
// Prefer primary path
|
||||
configPath = primaryConfigPath;
|
||||
backupConfigPath = path.join(entryPath, backupConfigName);
|
||||
} else if (hasSecondaryConfig) {
|
||||
// Work with secondary path (some monorepo setups)
|
||||
configPath = secondaryConfigPath;
|
||||
backupConfigPath = path.join(workPath, backupConfigName);
|
||||
} else {
|
||||
// Default to primary path for creation
|
||||
configPath = primaryConfigPath;
|
||||
backupConfigPath = path.join(entryPath, backupConfigName);
|
||||
}
|
||||
|
||||
if (fs.existsSync(configPath)) {
|
||||
await fs.rename(configPath, backupConfigPath);
|
||||
await fs.writeFile(configPath, getCustomData(backupConfigName, target));
|
||||
} else {
|
||||
await fs.writeFile(configPath, getDefaultData(target));
|
||||
}
|
||||
return target;
|
||||
}
|
||||
24
packages/next/src/edge-function-source/constants.ts
Normal file
24
packages/next/src/edge-function-source/constants.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
const KIB = 1024;
|
||||
const MIB = 1024 * KIB;
|
||||
|
||||
/**
|
||||
* The limit after compression. it has to be kibibyte instead of kilobyte
|
||||
* See https://github.com/cloudflare/wrangler/blob/8907b12add3d70ee21ac597b69cd66f6807571f4/src/wranglerjs/output.rs#L44
|
||||
*/
|
||||
const EDGE_FUNCTION_SCRIPT_SIZE_LIMIT = MIB;
|
||||
|
||||
/**
|
||||
* This safety buffer must cover the size of our whole runtime layer compressed
|
||||
* plus some extra space to allow it to grow in the future. At the time of
|
||||
* writing this comment the compressed size size is ~7KiB so 20KiB should
|
||||
* be more than enough.
|
||||
*/
|
||||
const EDGE_FUNCTION_SCRIPT_SIZE_BUFFER = 20 * KIB;
|
||||
|
||||
/**
|
||||
* The max size we allow for compressed user code is the compressed script
|
||||
* limit minus the compressed safety buffer. We must check this limit after
|
||||
* compressing the user code.
|
||||
*/
|
||||
export const EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT =
|
||||
EDGE_FUNCTION_SCRIPT_SIZE_LIMIT - EDGE_FUNCTION_SCRIPT_SIZE_BUFFER;
|
||||
@@ -0,0 +1,84 @@
|
||||
import type { NextjsParams } from './get-edge-function';
|
||||
import { readFile } from 'fs-extra';
|
||||
import { ConcatSource, Source } from 'webpack-sources';
|
||||
import { fileToSource, raw, sourcemapped } from '../sourcemapped';
|
||||
import { join } from 'path';
|
||||
import { EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT } from './constants';
|
||||
import zlib from 'zlib';
|
||||
import { promisify } from 'util';
|
||||
import bytes from 'pretty-bytes';
|
||||
|
||||
// @ts-expect-error this is a prebuilt file, based on `../../scripts/build-edge-function-template.js`
|
||||
import template from '../../dist/___get-nextjs-edge-function.js';
|
||||
|
||||
const gzip = promisify<zlib.InputType, Buffer>(zlib.gzip);
|
||||
|
||||
/**
|
||||
* Allows to get the source code for a Next.js Edge Function where the output
|
||||
* is defined by a set of filePaths that compose all chunks. Those will write
|
||||
* to a global namespace _ENTRIES. The Next.js parameters will allow to adapt
|
||||
* the function into the core Edge Function signature.
|
||||
*
|
||||
* @param filePaths Array of relative file paths for the function chunks.
|
||||
* @param params Next.js parameters to adapt it to core edge functions.
|
||||
* @param outputDir The output directory the files in `filePaths` stored in.
|
||||
* @returns The source code of the edge function.
|
||||
*/
|
||||
export async function getNextjsEdgeFunctionSource(
|
||||
filePaths: string[],
|
||||
params: NextjsParams,
|
||||
outputDir: string,
|
||||
wasm?: { filePath: string; name: string }[]
|
||||
): Promise<Source> {
|
||||
const chunks = new ConcatSource(raw(`let _ENTRIES = {};`));
|
||||
for (const filePath of filePaths) {
|
||||
const fullFilePath = join(outputDir, filePath);
|
||||
const content = await readFile(fullFilePath, 'utf8');
|
||||
chunks.add(raw(`\n/**/;`));
|
||||
chunks.add(await fileToSource(content, filePath, fullFilePath));
|
||||
}
|
||||
|
||||
const text = chunks.source();
|
||||
|
||||
/**
|
||||
* We validate at this point because we want to verify against user code.
|
||||
* It should not count the Worker wrapper nor the Next.js wrapper.
|
||||
*/
|
||||
await validateScript(text);
|
||||
|
||||
// Wrap to fake module.exports
|
||||
const getPageMatchCode = `(function () {
|
||||
const module = { exports: {}, loaded: false };
|
||||
const fn = (function(module,exports) {${template}\n});
|
||||
fn(module, module.exports);
|
||||
return module.exports;
|
||||
})`;
|
||||
|
||||
return sourcemapped`
|
||||
${raw(getWasmImportStatements(wasm))}
|
||||
${chunks};
|
||||
export default ${raw(getPageMatchCode)}.call({}).default(
|
||||
${raw(JSON.stringify(params))}
|
||||
)`;
|
||||
}
|
||||
|
||||
function getWasmImportStatements(wasm: { name: string }[] = []) {
|
||||
return wasm
|
||||
.filter(({ name }) => name.startsWith('wasm_'))
|
||||
.map(({ name }) => {
|
||||
const pathname = `/wasm/${name}.wasm`;
|
||||
return `const ${name} = require(${JSON.stringify(pathname)});`;
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
async function validateScript(content: string) {
|
||||
const gzipped = await gzip(content);
|
||||
if (gzipped.length > EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT) {
|
||||
throw new Error(
|
||||
`Exceeds maximum edge function script size: ${bytes(
|
||||
gzipped.length
|
||||
)} / ${bytes(EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
242
packages/next/src/edge-function-source/get-edge-function.ts
Normal file
242
packages/next/src/edge-function-source/get-edge-function.ts
Normal file
@@ -0,0 +1,242 @@
|
||||
/// <reference lib="DOM" />
|
||||
|
||||
import { toPlainHeaders } from './to-plain-headers';
|
||||
|
||||
export interface NextjsParams {
|
||||
/**
|
||||
* The name of the function exposed in _ENTRIES that will be wrapped.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* An array with all static pages that the Next.js application contains.
|
||||
* This is required to estimate if a pathname will match a page.
|
||||
*/
|
||||
staticRoutes: { page: string; namedRegex?: string }[];
|
||||
/**
|
||||
* An array with dynamic page names and their matching regular expression.
|
||||
* This is required to estimate if a request will match a dynamic page.
|
||||
*/
|
||||
dynamicRoutes?: { page: string; namedRegex?: string }[];
|
||||
/**
|
||||
* The Next.js minimal configuration that the Middleware Edge Function
|
||||
* requires to parse the URL. This must include the locale config and
|
||||
* the basePath.
|
||||
*/
|
||||
nextConfig: NextConfig | null;
|
||||
}
|
||||
|
||||
type EdgeFunction = (
|
||||
request: Request,
|
||||
context: { waitUntil(promise: Promise<unknown>): void }
|
||||
) => Promise<Response>;
|
||||
|
||||
/**
|
||||
* A template to adapt the Next.js Edge Function signature into the core Edge
|
||||
* Function signature. This will automatically inject parameters that are
|
||||
* missing in default Edge Functions from the provided configuration
|
||||
* parameters. Static and Dynamic RegExp are calculated in the module scope
|
||||
* to avoid recomputing them for each function invocation.
|
||||
*/
|
||||
export default function getNextjsEdgeFunction(
|
||||
params: NextjsParams
|
||||
): EdgeFunction {
|
||||
const staticRoutes = params.staticRoutes.map(route => ({
|
||||
regexp: new RegExp(route.namedRegex!),
|
||||
page: route.page,
|
||||
}));
|
||||
|
||||
const dynamicRoutes =
|
||||
params.dynamicRoutes?.map(route => ({
|
||||
regexp: new RegExp(route.namedRegex!),
|
||||
page: route.page,
|
||||
})) || [];
|
||||
|
||||
return async function edgeFunction(request, context) {
|
||||
let pathname = new URL(request.url).pathname;
|
||||
let pageMatch: PageMatch = {};
|
||||
|
||||
// Remove the basePath from the URL
|
||||
if (params.nextConfig?.basePath) {
|
||||
if (pathname.startsWith(params.nextConfig.basePath)) {
|
||||
pathname = pathname.replace(params.nextConfig.basePath, '') || '/';
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the locale from the URL
|
||||
if (params.nextConfig?.i18n) {
|
||||
for (const locale of params.nextConfig.i18n.locales) {
|
||||
const regexp = new RegExp(`^/${locale}($|/)`, 'i');
|
||||
if (pathname.match(regexp)) {
|
||||
pathname = pathname.replace(regexp, '/') || '/';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find the page match that will happen if there are no assets matching
|
||||
for (const route of staticRoutes) {
|
||||
const result = route.regexp.exec(pathname);
|
||||
if (result) {
|
||||
pageMatch.name = route.page;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pageMatch.name) {
|
||||
const isApi = isApiRoute(pathname);
|
||||
for (const route of dynamicRoutes || []) {
|
||||
/**
|
||||
* Dynamic API routes should not be checked against dynamic non API
|
||||
* routes so we skip it in such case. For example, a request to
|
||||
* /api/test should not match /pages/[slug].test having:
|
||||
* - pages/api/foo.js
|
||||
* - pages/[slug]/test.js
|
||||
*/
|
||||
if (isApi && !isApiRoute(route.page)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const result = route.regexp.exec(pathname);
|
||||
if (result) {
|
||||
pageMatch = {
|
||||
name: route.page,
|
||||
params: result.groups,
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke the function injecting missing parameters
|
||||
const result = await _ENTRIES[`middleware_${params.name}`].default.call(
|
||||
{},
|
||||
{
|
||||
request: {
|
||||
url: request.url,
|
||||
method: request.method,
|
||||
headers: toPlainHeaders(request.headers),
|
||||
ip: header(request.headers, IncomingHeaders.Ip),
|
||||
geo: {
|
||||
city: header(request.headers, IncomingHeaders.City, true),
|
||||
country: header(request.headers, IncomingHeaders.Country, true),
|
||||
latitude: header(request.headers, IncomingHeaders.Latitude),
|
||||
longitude: header(request.headers, IncomingHeaders.Longitude),
|
||||
region: header(request.headers, IncomingHeaders.Region, true),
|
||||
},
|
||||
nextConfig: params.nextConfig,
|
||||
page: pageMatch,
|
||||
body: request.body,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
context.waitUntil(result.waitUntil);
|
||||
|
||||
return result.response;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to get a header value by name but falling back to `undefined` when
|
||||
* the value does not exist. Optionally, we can make this function decode
|
||||
* what it reads for certain cases.
|
||||
*
|
||||
* @param headers The Headers object.
|
||||
* @param name The name of the header to extract.
|
||||
* @param decode Tells if we should decode the value.
|
||||
* @returns The header value or undefined.
|
||||
*/
|
||||
function header(headers: Headers, name: string, decode = false) {
|
||||
const value = headers.get(name) || undefined;
|
||||
return decode && value ? decodeURIComponent(value) : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Next.js current output will write in the global variable _ENTRIES all of
|
||||
* the middleware that exist in the application. This global describes its
|
||||
* signature which we should adapt into the core Edge Function.
|
||||
*/
|
||||
declare let _ENTRIES: {
|
||||
[key: string]: {
|
||||
default: (params: {
|
||||
request: {
|
||||
url: string;
|
||||
method: string;
|
||||
headers: {
|
||||
[header: string]: string | string[] | undefined;
|
||||
};
|
||||
ip?: string;
|
||||
geo?: {
|
||||
city?: string;
|
||||
country?: string;
|
||||
region?: string;
|
||||
latitude?: string;
|
||||
longitude?: string;
|
||||
};
|
||||
nextConfig?: NextConfig | null;
|
||||
page?: PageMatch;
|
||||
body: ReadableStream<Uint8Array> | null;
|
||||
};
|
||||
}) => Promise<{ response: Response; waitUntil: Promise<any> }>;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* A partial Next.js configuration object that contains the required info
|
||||
* to parse the URL and figure out the pathname.
|
||||
*/
|
||||
interface NextConfig {
|
||||
basePath?: string;
|
||||
i18n?: {
|
||||
defaultLocale: string;
|
||||
domains?: {
|
||||
defaultLocale: string;
|
||||
domain: string;
|
||||
http?: boolean;
|
||||
locales?: string[];
|
||||
}[];
|
||||
localeDetection?: boolean;
|
||||
locales: string[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Information about the page and parameters that the Middleware Edge
|
||||
* Function will match in case it doesn't intercept the request.
|
||||
* TODO We must consider if this should be removed as it is misleading.
|
||||
*/
|
||||
interface PageMatch {
|
||||
name?: string;
|
||||
params?: { [key: string]: string };
|
||||
}
|
||||
|
||||
function isApiRoute(path: string) {
|
||||
return path === '/api' || path.startsWith('/api/');
|
||||
}
|
||||
|
||||
enum IncomingHeaders {
|
||||
/**
|
||||
* City of the original client IP calculated by Vercel Proxy.
|
||||
*/
|
||||
City = 'x-vercel-ip-city',
|
||||
/**
|
||||
* Country of the original client IP calculated by Vercel Proxy.
|
||||
*/
|
||||
Country = 'x-vercel-ip-country',
|
||||
/**
|
||||
* Ip from Vercel Proxy. Do not confuse it with the client Ip.
|
||||
*/
|
||||
Ip = 'x-real-ip',
|
||||
/**
|
||||
* Latitude of the original client IP calculated by Vercel Proxy.
|
||||
*/
|
||||
Latitude = 'x-vercel-ip-latitude',
|
||||
/**
|
||||
* Longitude of the original client IP calculated by Vercel Proxy.
|
||||
*/
|
||||
Longitude = 'x-vercel-ip-longitude',
|
||||
/**
|
||||
* Region of the original client IP calculated by Vercel Proxy.
|
||||
*/
|
||||
Region = 'x-vercel-ip-country-region',
|
||||
}
|
||||
94
packages/next/src/edge-function-source/to-plain-headers.ts
Normal file
94
packages/next/src/edge-function-source/to-plain-headers.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
interface PlainHeaders {
|
||||
[header: string]: string | string[] | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a standard Headers object into a plean Headers object. This is
|
||||
* done to support a plain format for headers which is used in the Edge
|
||||
* Function signature.
|
||||
*
|
||||
* @param headers Headers from the original request.
|
||||
* @returns The same headers formatted as Node Headers.
|
||||
*/
|
||||
export function toPlainHeaders(headers?: Headers): PlainHeaders {
|
||||
const result: PlainHeaders = {};
|
||||
if (!headers) return result;
|
||||
headers.forEach((value, key) => {
|
||||
result[key] = value;
|
||||
if (key.toLowerCase() === 'set-cookie') {
|
||||
result[key] = splitCookiesString(value);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set-Cookie header field-values are sometimes comma joined in one string.
|
||||
* This splits them without choking on commas that are within a single
|
||||
* set-cookie field-value, such as in the Expires portion. This is uncommon,
|
||||
* but explicitly allowed (https://tools.ietf.org/html/rfc2616#section-4.2)
|
||||
*/
|
||||
export function splitCookiesString(cookiesString: string) {
|
||||
const cookiesStrings: string[] = [];
|
||||
|
||||
let pos = 0;
|
||||
let start: number;
|
||||
let ch: string;
|
||||
let lastComma: number;
|
||||
let nextStart: number;
|
||||
let cookiesSeparatorFound: boolean;
|
||||
|
||||
function skipWhitespace() {
|
||||
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos)))
|
||||
pos += 1;
|
||||
return pos < cookiesString.length;
|
||||
}
|
||||
|
||||
function notSpecialChar() {
|
||||
ch = cookiesString.charAt(pos);
|
||||
return ch !== '=' && ch !== ';' && ch !== ',';
|
||||
}
|
||||
|
||||
while (pos < cookiesString.length) {
|
||||
start = pos;
|
||||
cookiesSeparatorFound = false;
|
||||
|
||||
while (skipWhitespace()) {
|
||||
ch = cookiesString.charAt(pos);
|
||||
if (ch === ',') {
|
||||
// ',' is a cookie separator if we have later first '=', not ';' or ','
|
||||
lastComma = pos;
|
||||
pos += 1;
|
||||
|
||||
skipWhitespace();
|
||||
nextStart = pos;
|
||||
|
||||
while (pos < cookiesString.length && notSpecialChar()) {
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
// currently special character
|
||||
if (pos < cookiesString.length && cookiesString.charAt(pos) === '=') {
|
||||
// we found cookies separator
|
||||
cookiesSeparatorFound = true;
|
||||
// pos is inside the next cookie, so back up and return it.
|
||||
pos = nextStart;
|
||||
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
||||
start = pos;
|
||||
} else {
|
||||
// in param ',' or param separator ';',
|
||||
// we continue from that comma
|
||||
pos = lastComma + 1;
|
||||
}
|
||||
} else {
|
||||
pos += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
||||
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
||||
}
|
||||
}
|
||||
|
||||
return cookiesStrings;
|
||||
}
|
||||
2642
packages/next/src/index.ts
Normal file
2642
packages/next/src/index.ts
Normal file
File diff suppressed because it is too large
Load Diff
15
packages/next/src/legacy-launcher.ts
Normal file
15
packages/next/src/legacy-launcher.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { IncomingMessage, ServerResponse } from 'http';
|
||||
import next from 'next-server';
|
||||
import url from 'url';
|
||||
|
||||
if (!process.env.NODE_ENV) {
|
||||
const region = process.env.VERCEL_REGION || process.env.NOW_REGION;
|
||||
process.env.NODE_ENV = region === 'dev1' ? 'development' : 'production';
|
||||
}
|
||||
|
||||
const app = next({});
|
||||
|
||||
module.exports = (req: IncomingMessage, res: ServerResponse) => {
|
||||
const parsedUrl = url.parse(req.url || '', true);
|
||||
app.render(req, res, 'PATHNAME_PLACEHOLDER', parsedUrl.query, parsedUrl);
|
||||
};
|
||||
336
packages/next/src/legacy-versions.ts
Normal file
336
packages/next/src/legacy-versions.ts
Normal file
@@ -0,0 +1,336 @@
|
||||
export default [
|
||||
'0.1.0',
|
||||
'0.1.1',
|
||||
'0.2.0',
|
||||
'0.2.1',
|
||||
'0.2.2',
|
||||
'0.2.3',
|
||||
'0.2.4',
|
||||
'0.2.5',
|
||||
'0.2.6',
|
||||
'0.2.7',
|
||||
'0.2.8',
|
||||
'0.2.9',
|
||||
'0.2.10',
|
||||
'0.2.11',
|
||||
'0.2.12',
|
||||
'0.2.13',
|
||||
'0.2.14',
|
||||
'0.3.0',
|
||||
'0.3.1',
|
||||
'0.3.2',
|
||||
'0.3.3',
|
||||
'0.4.0',
|
||||
'0.4.1',
|
||||
'0.9.9',
|
||||
'0.9.10',
|
||||
'0.9.11',
|
||||
'1.0.0',
|
||||
'1.0.1',
|
||||
'1.0.2',
|
||||
'1.1.0',
|
||||
'1.1.1',
|
||||
'1.1.2',
|
||||
'1.2.0',
|
||||
'1.2.1',
|
||||
'1.2.2',
|
||||
'1.2.3',
|
||||
'2.0.0-beta.0',
|
||||
'2.0.0-beta.1',
|
||||
'2.0.0-beta.2',
|
||||
'2.0.0-beta.3',
|
||||
'2.0.0-beta.4',
|
||||
'2.0.0-beta.5',
|
||||
'2.0.0-beta.6',
|
||||
'2.0.0-beta.7',
|
||||
'2.0.0-beta.8',
|
||||
'2.0.0-beta.9',
|
||||
'2.0.0-beta.10',
|
||||
'2.0.0-beta.11',
|
||||
'2.0.0-beta.12',
|
||||
'2.0.0-beta.13',
|
||||
'2.0.0-beta.14',
|
||||
'2.0.0-beta.15',
|
||||
'2.0.0-beta.16',
|
||||
'2.0.0-beta.17',
|
||||
'2.0.0-beta.18',
|
||||
'2.0.0-beta.19',
|
||||
'2.0.0-beta.20',
|
||||
'2.0.0-beta.21',
|
||||
'2.0.0-beta.22',
|
||||
'2.0.0-beta.23',
|
||||
'2.0.0-beta.24',
|
||||
'2.0.0-beta.25',
|
||||
'2.0.0-beta.26',
|
||||
'2.0.0-beta.27',
|
||||
'2.0.0-beta.28',
|
||||
'2.0.0-beta.29',
|
||||
'2.0.0-beta.30',
|
||||
'2.0.0-beta.31',
|
||||
'2.0.0-beta.32',
|
||||
'2.0.0-beta.33',
|
||||
'2.0.0-beta.34',
|
||||
'2.0.0-beta.35',
|
||||
'2.0.0-beta.36',
|
||||
'2.0.0-beta.37',
|
||||
'2.0.0-beta.38',
|
||||
'2.0.0-beta.39',
|
||||
'2.0.0-beta.40',
|
||||
'2.0.0-beta.41',
|
||||
'2.0.0-beta.42',
|
||||
'2.0.0',
|
||||
'2.0.1',
|
||||
'2.1.0',
|
||||
'2.1.1',
|
||||
'2.2.0',
|
||||
'2.3.0-alpha1',
|
||||
'2.3.0',
|
||||
'2.3.1',
|
||||
'2.4.0',
|
||||
'2.4.1',
|
||||
'2.4.2',
|
||||
'2.4.3',
|
||||
'2.4.4',
|
||||
'2.4.5',
|
||||
'2.4.6',
|
||||
'2.4.7',
|
||||
'2.4.8',
|
||||
'2.4.9',
|
||||
'3.0.0-beta1',
|
||||
'3.0.0-beta10',
|
||||
'3.0.0-beta11',
|
||||
'3.0.0-beta12',
|
||||
'3.0.0-beta13',
|
||||
'3.0.0-beta14',
|
||||
'3.0.0-beta15',
|
||||
'3.0.0-beta16',
|
||||
'3.0.0-beta2',
|
||||
'3.0.0-beta3',
|
||||
'3.0.0-beta4',
|
||||
'3.0.0-beta5',
|
||||
'3.0.0-beta6',
|
||||
'3.0.0-beta7',
|
||||
'3.0.0-beta8',
|
||||
'3.0.0-beta9',
|
||||
'3.0.1-beta.1',
|
||||
'3.0.1-beta.2',
|
||||
'3.0.1-beta.3',
|
||||
'3.0.1-beta.4',
|
||||
'3.0.1-beta.5',
|
||||
'3.0.1-beta.6',
|
||||
'3.0.1-beta.7',
|
||||
'3.0.1-beta.8',
|
||||
'3.0.1-beta.9',
|
||||
'3.0.1-beta.10',
|
||||
'3.0.1-beta.11',
|
||||
'3.0.1-beta.12',
|
||||
'3.0.1-beta.13',
|
||||
'3.0.1-beta.14',
|
||||
'3.0.1-beta.15',
|
||||
'3.0.1-beta.16',
|
||||
'3.0.1-beta.17',
|
||||
'3.0.1-beta.18',
|
||||
'3.0.1-beta.19',
|
||||
'3.0.1-beta.20',
|
||||
'3.0.1-beta.21',
|
||||
'3.0.1',
|
||||
'3.0.2',
|
||||
'3.0.3',
|
||||
'3.0.4',
|
||||
'3.0.5',
|
||||
'3.0.6',
|
||||
'3.1.0',
|
||||
'3.2.0',
|
||||
'3.2.1',
|
||||
'3.2.2',
|
||||
'3.2.3',
|
||||
'4.0.0-beta.1',
|
||||
'4.0.0-beta.2',
|
||||
'4.0.0-beta.3',
|
||||
'4.0.0-beta.4',
|
||||
'4.0.0-beta.5',
|
||||
'4.0.0-beta.6',
|
||||
'4.0.0',
|
||||
'4.0.1',
|
||||
'4.0.2',
|
||||
'4.0.3',
|
||||
'4.0.4',
|
||||
'4.0.5',
|
||||
'4.1.0',
|
||||
'4.1.1',
|
||||
'4.1.2',
|
||||
'4.1.3',
|
||||
'4.1.4-canary.1',
|
||||
'4.1.4-canary.2',
|
||||
'4.1.4',
|
||||
'4.2.0-canary.1',
|
||||
'4.2.0-zones.2',
|
||||
'4.2.0',
|
||||
'4.2.1',
|
||||
'4.2.2',
|
||||
'4.2.3',
|
||||
'4.3.0-canary.1',
|
||||
'4.3.0-universal-alpha.1',
|
||||
'4.3.0-universal-alpha.2',
|
||||
'4.3.0-universal-alpha.3',
|
||||
'4.3.0-universal-alpha.4',
|
||||
'4.3.0-zones.1',
|
||||
'4.4.0-canary.2',
|
||||
'4.4.0-canary.3',
|
||||
'5.0.0-universal-alpha.1',
|
||||
'5.0.0-universal-alpha.2',
|
||||
'5.0.0-universal-alpha.3',
|
||||
'5.0.0-universal-alpha.4',
|
||||
'5.0.0-universal-alpha.5',
|
||||
'5.0.0-universal-alpha.6',
|
||||
'5.0.0-universal-alpha.7',
|
||||
'5.0.0-universal-alpha.8',
|
||||
'5.0.0-universal-alpha.9',
|
||||
'5.0.0-universal-alpha.10',
|
||||
'5.0.0-universal-alpha.11',
|
||||
'5.0.0-universal-alpha.12',
|
||||
'5.0.0-universal-alpha.13',
|
||||
'5.0.0-universal-alpha.14',
|
||||
'5.0.0-universal-alpha.15',
|
||||
'5.0.0-universal-alpha.16',
|
||||
'5.0.0-universal-alpha.17',
|
||||
'5.0.0-universal-alpha.18',
|
||||
'5.0.0-universal-alpha.19',
|
||||
'5.0.0-universal-alpha.20',
|
||||
'5.0.0-universal-alpha.21',
|
||||
'5.0.0-universal-alpha.22',
|
||||
'5.0.0-universal-alpha.23',
|
||||
'5.0.0-zones.1',
|
||||
'5.0.0',
|
||||
'5.0.1-canary.1',
|
||||
'5.0.1-canary.2',
|
||||
'5.0.1-canary.3',
|
||||
'5.0.1-canary.4',
|
||||
'5.0.1-canary.5',
|
||||
'5.0.1-canary.6',
|
||||
'5.0.1-canary.7',
|
||||
'5.0.1-canary.8',
|
||||
'5.0.1-canary.9',
|
||||
'5.0.1-canary.10',
|
||||
'5.0.1-canary.11',
|
||||
'5.0.1-canary.12',
|
||||
'5.0.1-canary.13',
|
||||
'5.0.1-canary.14',
|
||||
'5.0.1-canary.15',
|
||||
'5.0.1-canary.16',
|
||||
'5.0.1-canary.17',
|
||||
'5.1.0',
|
||||
'6.0.0-canary.1',
|
||||
'6.0.0-canary.2',
|
||||
'6.0.0-canary.3',
|
||||
'6.0.0-canary.4',
|
||||
'6.0.0-canary.5',
|
||||
'6.0.0-canary.6',
|
||||
'6.0.0-canary.7',
|
||||
'6.0.0',
|
||||
'6.0.1-canary.0',
|
||||
'6.0.1-canary.1',
|
||||
'6.0.1-canary.2',
|
||||
'6.0.1',
|
||||
'6.0.2-canary.0',
|
||||
'6.0.2',
|
||||
'6.0.3-canary.0',
|
||||
'6.0.3-canary.1',
|
||||
'6.0.3',
|
||||
'6.0.4-canary.0',
|
||||
'6.0.4-canary.1',
|
||||
'6.0.4-canary.2',
|
||||
'6.0.4-canary.3',
|
||||
'6.0.4-canary.4',
|
||||
'6.0.4-canary.5',
|
||||
'6.0.4-canary.6',
|
||||
'6.0.4-canary.7',
|
||||
'6.0.4-canary.8',
|
||||
'6.0.4-canary.9',
|
||||
'6.1.0-canary.0',
|
||||
'6.1.0',
|
||||
'6.1.1-canary.0',
|
||||
'6.1.1-canary.1',
|
||||
'6.1.1-canary.2',
|
||||
'6.1.1-canary.3',
|
||||
'6.1.1-canary.4',
|
||||
'6.1.1-canary.5',
|
||||
'6.1.1',
|
||||
'6.1.2',
|
||||
'7.0.0-canary.0',
|
||||
'7.0.0-canary.1',
|
||||
'7.0.0-canary.2',
|
||||
'7.0.0-canary.3',
|
||||
'7.0.0-canary.4',
|
||||
'7.0.0-canary.5',
|
||||
'7.0.0-canary.6',
|
||||
'7.0.0-canary.7',
|
||||
'7.0.0-canary.8',
|
||||
'7.0.0-canary.9',
|
||||
'7.0.0-canary.10',
|
||||
'7.0.0-canary.11',
|
||||
'7.0.0-canary.12',
|
||||
'7.0.0-canary.13',
|
||||
'7.0.0-canary.14',
|
||||
'7.0.0-canary.15',
|
||||
'7.0.0-canary.16',
|
||||
'7.0.0-canary.18',
|
||||
'7.0.0-canary.19',
|
||||
'7.0.0-canary.20',
|
||||
'7.0.0',
|
||||
'7.0.1-canary.0',
|
||||
'7.0.1-canary.1',
|
||||
'7.0.1-canary.2',
|
||||
'7.0.1-canary.3',
|
||||
'7.0.1-canary.4',
|
||||
'7.0.1-canary.5',
|
||||
'7.0.1-canary.6',
|
||||
'7.0.1',
|
||||
'7.0.2-alpha.1',
|
||||
'7.0.2-alpha.3',
|
||||
'7.0.2-canary.5',
|
||||
'7.0.2-canary.6',
|
||||
'7.0.2-canary.7',
|
||||
'7.0.2-canary.8',
|
||||
'7.0.2-canary.9',
|
||||
'7.0.2-canary.10',
|
||||
'7.0.2-canary.11',
|
||||
'7.0.2-canary.12',
|
||||
'7.0.2-canary.13',
|
||||
'7.0.2-canary.14',
|
||||
'7.0.2-canary.15',
|
||||
'7.0.2-canary.16',
|
||||
'7.0.2-canary.17',
|
||||
'7.0.2-canary.18',
|
||||
'7.0.2-canary.19',
|
||||
'7.0.2-canary.20',
|
||||
'7.0.2-canary.21',
|
||||
'7.0.2-canary.22',
|
||||
'7.0.2-canary.23',
|
||||
'7.0.2-canary.24',
|
||||
'7.0.2-canary.25',
|
||||
'7.0.2-canary.26',
|
||||
'7.0.2-canary.27',
|
||||
'7.0.2-canary.28',
|
||||
'7.0.2-canary.29',
|
||||
'7.0.2-canary.31',
|
||||
'7.0.2-canary.33',
|
||||
'7.0.2-canary.34',
|
||||
'7.0.2-canary.35',
|
||||
'7.0.2-canary.36',
|
||||
'7.0.2-canary.37',
|
||||
'7.0.2-canary.38',
|
||||
'7.0.2-canary.39',
|
||||
'7.0.2-canary.40',
|
||||
'7.0.2-canary.41',
|
||||
'7.0.2-canary.42',
|
||||
'7.0.2-canary.43',
|
||||
'7.0.2-canary.44',
|
||||
'7.0.2-canary.45',
|
||||
'7.0.2-canary.46',
|
||||
'7.0.2-canary.47',
|
||||
'7.0.2-canary.48',
|
||||
'7.0.2-canary.49',
|
||||
'7.0.2-canary.50',
|
||||
'7.0.2',
|
||||
];
|
||||
1288
packages/next/src/server-build.ts
Normal file
1288
packages/next/src/server-build.ts
Normal file
File diff suppressed because it is too large
Load Diff
43
packages/next/src/server-launcher.ts
Normal file
43
packages/next/src/server-launcher.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { IncomingMessage, ServerResponse } from 'http';
|
||||
// The Next.js builder can emit the project in a subdirectory depending on how
|
||||
// many folder levels of `node_modules` are traced. To ensure `process.cwd()`
|
||||
// returns the proper path, we change the directory to the folder with the
|
||||
// launcher. This mimics `yarn workspace run` behavior.
|
||||
process.chdir(__dirname);
|
||||
|
||||
const region = process.env.VERCEL_REGION || process.env.NOW_REGION;
|
||||
|
||||
if (!process.env.NODE_ENV) {
|
||||
process.env.NODE_ENV = region === 'dev1' ? 'development' : 'production';
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' && region !== 'dev1') {
|
||||
console.warn(
|
||||
`Warning: NODE_ENV was incorrectly set to "${process.env.NODE_ENV}", this value is being overridden to "production"`
|
||||
);
|
||||
process.env.NODE_ENV = 'production';
|
||||
}
|
||||
|
||||
// eslint-disable-next-line
|
||||
const NextServer = require('__NEXT_SERVER_PATH__').default;
|
||||
const nextServer = new NextServer({
|
||||
// @ts-ignore __NEXT_CONFIG__ value is injected
|
||||
conf: __NEXT_CONFIG__,
|
||||
dir: '.',
|
||||
minimalMode: true,
|
||||
customServer: false,
|
||||
});
|
||||
const requestHandler = nextServer.getRequestHandler();
|
||||
|
||||
module.exports = async (req: IncomingMessage, res: ServerResponse) => {
|
||||
try {
|
||||
// entryDirectory handler
|
||||
await requestHandler(req, res);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
// crash the lambda immediately to clean up any bad module state,
|
||||
// this was previously handled in ___vc_bridge on an unhandled rejection
|
||||
// but we can do this quicker by triggering here
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
101
packages/next/src/sourcemapped.ts
Normal file
101
packages/next/src/sourcemapped.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import type { RawSourceMap } from 'source-map';
|
||||
import convertSourceMap from 'convert-source-map';
|
||||
import fs from 'fs-extra';
|
||||
import {
|
||||
ConcatSource,
|
||||
OriginalSource,
|
||||
SourceMapSource,
|
||||
Source,
|
||||
} from 'webpack-sources';
|
||||
|
||||
/**
|
||||
* A template literal tag that preserves existing source maps, if any. This
|
||||
* allows to compose multiple sources and preserve the source maps, so we can
|
||||
* resolve the correct line numbers in the stack traces later on.
|
||||
*
|
||||
* @param strings The string literals.
|
||||
* @param sources All the sources that may optionally have source maps. Use
|
||||
* `raw` to pass a string that should be inserted raw (with no source map
|
||||
* attached).
|
||||
*/
|
||||
export function sourcemapped(
|
||||
strings: TemplateStringsArray,
|
||||
...sources: Source[]
|
||||
): Source {
|
||||
const concat = new ConcatSource();
|
||||
|
||||
for (let i = 0; i < Math.max(strings.length, sources.length); i++) {
|
||||
const string = strings[i];
|
||||
const source = sources[i];
|
||||
if (string) concat.add(raw(string));
|
||||
if (source) concat.add(source);
|
||||
}
|
||||
|
||||
return concat;
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper to create a Source from a string with no source map.
|
||||
* This allows to obfuscate the source code from the user and print `[native code]`
|
||||
* when resolving the stack trace.
|
||||
*/
|
||||
export function raw(value: string) {
|
||||
return new OriginalSource(value, '[native code]');
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a file with contents and tries to extract its source maps it will
|
||||
* first try to use a `${fullFilePath}.map` file if it exists. Then, it will
|
||||
* try to use the inline source map comment.
|
||||
*
|
||||
* @param content The file contents.
|
||||
* @param sourceName the name of the source.
|
||||
* @param fullFilePath The full path to the file.
|
||||
*/
|
||||
export async function fileToSource(
|
||||
content: string,
|
||||
sourceName: string,
|
||||
fullFilePath?: string
|
||||
): Promise<Source> {
|
||||
const sourcemap = await getSourceMap(content, fullFilePath);
|
||||
const cleanContent = convertSourceMap.removeComments(content);
|
||||
return sourcemap
|
||||
? new SourceMapSource(cleanContent, sourceName, sourcemap)
|
||||
: new OriginalSource(cleanContent, sourceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a source map for a given content and file path. First it will try to
|
||||
* use a `${fullFilePath}.map` file if it exists. Then, it will try to use
|
||||
* the inline source map comment.
|
||||
*/
|
||||
async function getSourceMap(
|
||||
content: string,
|
||||
fullFilePath?: string
|
||||
): Promise<RawSourceMap | null> {
|
||||
try {
|
||||
if (fullFilePath && (await fs.pathExists(`${fullFilePath}.map`))) {
|
||||
const mapJson = await fs.readFile(`${fullFilePath}.map`, 'utf8');
|
||||
return convertSourceMap.fromJSON(mapJson).toObject();
|
||||
}
|
||||
return convertSourceMap.fromComment(content).toObject();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringifies a source map, removing unnecessary data:
|
||||
* * `sourcesContent` is not needed to trace back frames.
|
||||
*/
|
||||
export function stringifySourceMap(
|
||||
sourceMap?: RawSourceMap | string | null
|
||||
): string | undefined {
|
||||
if (!sourceMap) return;
|
||||
const obj =
|
||||
typeof sourceMap === 'object'
|
||||
? { ...sourceMap }
|
||||
: convertSourceMap.fromJSON(sourceMap).toObject();
|
||||
delete obj.sourcesContent;
|
||||
return JSON.stringify(obj);
|
||||
}
|
||||
28
packages/next/src/templated-launcher-shared.ts
Normal file
28
packages/next/src/templated-launcher-shared.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
// The Next.js builder can emit the project in a subdirectory depending on how
|
||||
// many folder levels of `node_modules` are traced. To ensure `process.cwd()`
|
||||
// returns the proper path, we change the directory to the folder with the
|
||||
// launcher. This mimics `yarn workspace run` behavior.
|
||||
process.chdir(__dirname);
|
||||
|
||||
const region = process.env.VERCEL_REGION || process.env.NOW_REGION;
|
||||
|
||||
if (!process.env.NODE_ENV) {
|
||||
process.env.NODE_ENV = region === 'dev1' ? 'development' : 'production';
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' && region !== 'dev1') {
|
||||
console.warn(
|
||||
`Warning: NODE_ENV was incorrectly set to "${process.env.NODE_ENV}", this value is being overridden to "production"`
|
||||
);
|
||||
process.env.NODE_ENV = 'production';
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line
|
||||
let page: any = {};
|
||||
// __LAUNCHER_PAGE_HANDLER__
|
||||
|
||||
// page.render is for React rendering
|
||||
// page.default is for /api rendering
|
||||
// page is for module.exports in /api
|
||||
module.exports = page.render || page.default || page;
|
||||
19
packages/next/src/templated-launcher.ts
Normal file
19
packages/next/src/templated-launcher.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// The Next.js builder can emit the project in a subdirectory depending on how
|
||||
// many folder levels of `node_modules` are traced. To ensure `process.cwd()`
|
||||
// returns the proper path, we change the directory to the folder with the
|
||||
// launcher. This mimics `yarn workspace run` behavior.
|
||||
process.chdir(__dirname);
|
||||
|
||||
if (!process.env.NODE_ENV) {
|
||||
const region = process.env.VERCEL_REGION || process.env.NOW_REGION;
|
||||
process.env.NODE_ENV = region === 'dev1' ? 'development' : 'production';
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const page = require(__LAUNCHER_PAGE_PATH__);
|
||||
|
||||
// page.render is for React rendering
|
||||
// page.default is for /api rendering
|
||||
// page is for module.exports in /api
|
||||
module.exports = page.render || page.default || page;
|
||||
2365
packages/next/src/utils.ts
Normal file
2365
packages/next/src/utils.ts
Normal file
File diff suppressed because it is too large
Load Diff
185
packages/next/test/fixtures/00-base-path-index-revalidate/index.test.js
vendored
Normal file
185
packages/next/test/fixtures/00-base-path-index-revalidate/index.test.js
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
/* eslint-env jest */
|
||||
const path = require('path');
|
||||
const cheerio = require('cheerio');
|
||||
const { check, deployAndTest } = require('../../utils');
|
||||
const fetch = require('../../../../../test/lib/deployment/fetch-retry');
|
||||
|
||||
async function checkForChange(url, initialValue, hardError) {
|
||||
if (isNaN(initialValue)) {
|
||||
throw new Error(
|
||||
`expected number for initialValue, received ${initialValue}`
|
||||
);
|
||||
}
|
||||
|
||||
return check(
|
||||
async () => {
|
||||
const res = await fetch(url);
|
||||
|
||||
if (res.status !== 200) {
|
||||
throw new Error(`Invalid status code ${res.status}`);
|
||||
}
|
||||
const $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
|
||||
if (isNaN(props.random)) {
|
||||
throw new Error(`Invalid random value ${props.random}`);
|
||||
}
|
||||
const newValue = props.random;
|
||||
return initialValue !== newValue ? 'success' : 'fail';
|
||||
},
|
||||
'success',
|
||||
hardError
|
||||
);
|
||||
}
|
||||
|
||||
const ctx = {};
|
||||
|
||||
describe(`${__dirname.split(path.sep).pop()}`, () => {
|
||||
it('should deploy and pass probe checks', async () => {
|
||||
const info = await deployAndTest(__dirname);
|
||||
Object.assign(ctx, info);
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /docs', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/docs/_next/data/testing-build-id/index.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
|
||||
const data = await dataRes.json();
|
||||
expect(data.pageProps.index).toBe(true);
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/docs`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
|
||||
expect(props.index).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({});
|
||||
expect($('#pathname').text()).toBe('pathname /');
|
||||
expect($('#asPath').text()).toBe('asPath /');
|
||||
|
||||
await checkForChange(`${ctx.deploymentUrl}/docs`, initialRandom);
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/docs`);
|
||||
expect(res2.status).toBe(200);
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
|
||||
expect(props2.index).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({});
|
||||
expect($('#pathname').text()).toBe('pathname /');
|
||||
expect($('#asPath').text()).toBe('asPath /');
|
||||
});
|
||||
|
||||
it('should load content properly from /docs/hello', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/docs/_next/data/testing-build-id/hello.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
|
||||
const data = await dataRes.json();
|
||||
expect(data.pageProps.id).toBe(true);
|
||||
expect(data.pageProps.params).toEqual({ id: 'hello' });
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/docs/hello`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
|
||||
expect(props.id).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({ id: 'hello' });
|
||||
expect($('#pathname').text()).toBe('pathname /[id]');
|
||||
expect($('#asPath').text()).toBe('asPath /hello');
|
||||
|
||||
await checkForChange(`${ctx.deploymentUrl}/docs/hello`, initialRandom);
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/docs/hello`);
|
||||
expect(res2.status).toBe(200);
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
|
||||
expect(props2.id).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({ id: 'hello' });
|
||||
expect($('#pathname').text()).toBe('pathname /[id]');
|
||||
expect($('#asPath').text()).toBe('asPath /hello');
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /docs/blog', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/docs/_next/data/testing-build-id/blog.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
|
||||
const data = await dataRes.json();
|
||||
expect(data.pageProps.blogIndex).toBe(true);
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/docs/blog`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
|
||||
expect(props.blogIndex).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({});
|
||||
expect($('#pathname').text()).toBe('pathname /blog');
|
||||
expect($('#asPath').text()).toBe('asPath /blog');
|
||||
|
||||
await checkForChange(`${ctx.deploymentUrl}/docs/blog`, initialRandom);
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/docs/blog`);
|
||||
expect(res2.status).toBe(200);
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
|
||||
expect(props2.blogIndex).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({});
|
||||
expect($('#pathname').text()).toBe('pathname /blog');
|
||||
expect($('#asPath').text()).toBe('asPath /blog');
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /docs/blog/another', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/docs/_next/data/testing-build-id/blog/another.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
|
||||
const data = await dataRes.json();
|
||||
expect(data.pageProps.blogSlug).toBe(true);
|
||||
expect(data.pageProps.params).toEqual({
|
||||
slug: 'another',
|
||||
});
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/docs/blog/another`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
|
||||
expect(props.blogSlug).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({ slug: 'another' });
|
||||
expect($('#pathname').text()).toBe('pathname /blog/[slug]');
|
||||
expect($('#asPath').text()).toBe('asPath /blog/another');
|
||||
|
||||
await checkForChange(
|
||||
`${ctx.deploymentUrl}/docs/blog/another`,
|
||||
initialRandom
|
||||
);
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/docs/blog/another`);
|
||||
expect(res2.status).toBe(200);
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
|
||||
expect(props2.blogSlug).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({ slug: 'another' });
|
||||
expect($('#pathname').text()).toBe('pathname /blog/[slug]');
|
||||
expect($('#asPath').text()).toBe('asPath /blog/another');
|
||||
});
|
||||
});
|
||||
7
packages/next/test/fixtures/00-base-path-index-revalidate/next.config.js
vendored
Normal file
7
packages/next/test/fixtures/00-base-path-index-revalidate/next.config.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
basePath: '/docs',
|
||||
|
||||
generateBuildId() {
|
||||
return 'testing-build-id';
|
||||
},
|
||||
};
|
||||
7
packages/next/test/fixtures/00-base-path-index-revalidate/package.json
vendored
Normal file
7
packages/next/test/fixtures/00-base-path-index-revalidate/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "latest",
|
||||
"react-dom": "latest"
|
||||
}
|
||||
}
|
||||
24
packages/next/test/fixtures/00-base-path-index-revalidate/pages/[id].js
vendored
Normal file
24
packages/next/test/fixtures/00-base-path-index-revalidate/pages/[id].js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Home(props) {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<>
|
||||
<p id="info">id page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="query">{JSON.stringify(router.query)}</p>
|
||||
<p id="pathname">{`pathname ${router.pathname}`}</p>
|
||||
<p id="asPath">{`asPath ${router.asPath}`}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export async function getServerSideProps({ params }) {
|
||||
return {
|
||||
props: {
|
||||
random: Math.random() + Date.now(),
|
||||
id: true,
|
||||
params,
|
||||
},
|
||||
};
|
||||
}
|
||||
32
packages/next/test/fixtures/00-base-path-index-revalidate/pages/blog/[slug].js
vendored
Normal file
32
packages/next/test/fixtures/00-base-path-index-revalidate/pages/blog/[slug].js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Home(props) {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<>
|
||||
<p id="info">blog slug page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="query">{JSON.stringify(router.query)}</p>
|
||||
<p id="pathname">{`pathname ${router.pathname}`}</p>
|
||||
<p id="asPath">{`asPath ${router.asPath}`}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params }) {
|
||||
return {
|
||||
revalidate: 1,
|
||||
props: {
|
||||
random: Math.random() + Date.now(),
|
||||
blogSlug: true,
|
||||
params,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function getStaticPaths() {
|
||||
return {
|
||||
paths: ['/blog/first'],
|
||||
fallback: 'blocking',
|
||||
};
|
||||
}
|
||||
24
packages/next/test/fixtures/00-base-path-index-revalidate/pages/blog/index.js
vendored
Normal file
24
packages/next/test/fixtures/00-base-path-index-revalidate/pages/blog/index.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Home(props) {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<>
|
||||
<p id="info">blog index page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="query">{JSON.stringify(router.query)}</p>
|
||||
<p id="pathname">{`pathname ${router.pathname}`}</p>
|
||||
<p id="asPath">{`asPath ${router.asPath}`}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export async function getStaticProps() {
|
||||
return {
|
||||
revalidate: 1,
|
||||
props: {
|
||||
random: Math.random() + Date.now(),
|
||||
blogIndex: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
24
packages/next/test/fixtures/00-base-path-index-revalidate/pages/index.js
vendored
Normal file
24
packages/next/test/fixtures/00-base-path-index-revalidate/pages/index.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Home(props) {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<>
|
||||
<p id="info">index page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="query">{JSON.stringify(router.query)}</p>
|
||||
<p id="pathname">{`pathname ${router.pathname}`}</p>
|
||||
<p id="asPath">{`asPath ${router.asPath}`}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export async function getStaticProps() {
|
||||
return {
|
||||
revalidate: 1,
|
||||
props: {
|
||||
random: Math.random() + Date.now(),
|
||||
index: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
9
packages/next/test/fixtures/00-base-path-index-revalidate/vercel.json
vendored
Normal file
9
packages/next/test/fixtures/00-base-path-index-revalidate/vercel.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"builds": [
|
||||
{
|
||||
"src": "package.json",
|
||||
"use": "@vercel/next"
|
||||
}
|
||||
],
|
||||
"probes": []
|
||||
}
|
||||
1
packages/next/test/fixtures/00-build-time-traces/content/hello.txt
vendored
Normal file
1
packages/next/test/fixtures/00-build-time-traces/content/hello.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
hello great big wide world!
|
||||
74
packages/next/test/fixtures/00-build-time-traces/index.test.js
vendored
Normal file
74
packages/next/test/fixtures/00-build-time-traces/index.test.js
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
const path = require('path');
|
||||
const cheerio = require('cheerio').default;
|
||||
const { deployAndTest, check } = require('../../utils');
|
||||
const fetch = require('../../../../../test/lib/deployment/fetch-retry');
|
||||
const ctx = {};
|
||||
|
||||
describe(`${__dirname.split(path.sep).pop()}`, () => {
|
||||
it('should deploy and pass probe checks', async () => {
|
||||
const info = await deployAndTest(__dirname);
|
||||
Object.assign(ctx, info);
|
||||
});
|
||||
|
||||
it('should revalidate content correctly', async () => {
|
||||
const res = await fetch(`${ctx.deploymentUrl}/another`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const previousNow = props.now;
|
||||
|
||||
expect(isNaN(props.now)).toBe(false);
|
||||
expect(props.content[0].trim()).toBe('hello great big wide world!');
|
||||
expect($('#page').text()).toBe('/another');
|
||||
|
||||
await check(async () => {
|
||||
const res = await fetch(`${ctx.deploymentUrl}/another`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
|
||||
if (isNaN(props.now)) {
|
||||
throw new Error('invalid props: ' + html);
|
||||
}
|
||||
return props.now !== previousNow &&
|
||||
props.content[0].trim() === 'hello great big wide world!'
|
||||
? 'success'
|
||||
: html;
|
||||
}, 'success');
|
||||
});
|
||||
|
||||
it('should revalidate content correctly', async () => {
|
||||
const res = await fetch(`${ctx.deploymentUrl}/post`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const previousNow = props.now;
|
||||
expect(props.content[0].trim()).toBe('hello great big wide world!');
|
||||
expect(isNaN(props.now)).toBe(false);
|
||||
expect($('#page').text()).toBe('/post');
|
||||
|
||||
await check(async () => {
|
||||
const res = await fetch(`${ctx.deploymentUrl}/post`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
const $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
expect($('#page').text()).toBe('/post');
|
||||
|
||||
if (isNaN(props.now)) {
|
||||
throw new Error('invalid props: ' + html);
|
||||
}
|
||||
return props.now !== previousNow &&
|
||||
props.content[0].trim() === 'hello great big wide world!'
|
||||
? 'success'
|
||||
: html;
|
||||
}, 'success');
|
||||
});
|
||||
});
|
||||
9
packages/next/test/fixtures/00-build-time-traces/lib/get-content.js
vendored
Normal file
9
packages/next/test/fixtures/00-build-time-traces/lib/get-content.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export async function getContent() {
|
||||
const files = fs.readdirSync(path.join(process.cwd(), 'content'));
|
||||
return files.map(file =>
|
||||
fs.readFileSync(path.join(process.cwd(), 'content', file), 'utf8')
|
||||
);
|
||||
}
|
||||
6
packages/next/test/fixtures/00-build-time-traces/next.config.js
vendored
Normal file
6
packages/next/test/fixtures/00-build-time-traces/next.config.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
reactStrictMode: true,
|
||||
experimental: {
|
||||
nftTracing: true,
|
||||
},
|
||||
};
|
||||
16
packages/next/test/fixtures/00-build-time-traces/package.json
vendored
Normal file
16
packages/next/test/fixtures/00-build-time-traces/package.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "test-trace",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2"
|
||||
}
|
||||
}
|
||||
5
packages/next/test/fixtures/00-build-time-traces/pages/_app.js
vendored
Normal file
5
packages/next/test/fixtures/00-build-time-traces/pages/_app.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return <Component {...pageProps} />;
|
||||
}
|
||||
|
||||
export default MyApp;
|
||||
20
packages/next/test/fixtures/00-build-time-traces/pages/another.js
vendored
Normal file
20
packages/next/test/fixtures/00-build-time-traces/pages/another.js
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { getContent } from '../lib/get-content';
|
||||
|
||||
export async function getStaticProps() {
|
||||
return {
|
||||
props: {
|
||||
now: Date.now(),
|
||||
content: await getContent(),
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
}
|
||||
|
||||
export default function Page(props) {
|
||||
return (
|
||||
<>
|
||||
<p id="page">/another</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
5
packages/next/test/fixtures/00-build-time-traces/pages/api/hello.js
vendored
Normal file
5
packages/next/test/fixtures/00-build-time-traces/pages/api/hello.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default function handler(req, res) {
|
||||
res.status(200).json({ name: 'John Doe' });
|
||||
}
|
||||
3
packages/next/test/fixtures/00-build-time-traces/pages/index.js
vendored
Normal file
3
packages/next/test/fixtures/00-build-time-traces/pages/index.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function Home() {
|
||||
return 'index page';
|
||||
}
|
||||
20
packages/next/test/fixtures/00-build-time-traces/pages/post.js
vendored
Normal file
20
packages/next/test/fixtures/00-build-time-traces/pages/post.js
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { getContent } from '../lib/get-content';
|
||||
|
||||
export async function getStaticProps() {
|
||||
return {
|
||||
props: {
|
||||
now: Date.now(),
|
||||
content: await getContent(),
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
}
|
||||
|
||||
export default function Page(props) {
|
||||
return (
|
||||
<>
|
||||
<p id="page">/post</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
BIN
packages/next/test/fixtures/00-build-time-traces/public/favicon.ico
vendored
Normal file
BIN
packages/next/test/fixtures/00-build-time-traces/public/favicon.ico
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
4
packages/next/test/fixtures/00-build-time-traces/public/vercel.svg
vendored
Normal file
4
packages/next/test/fixtures/00-build-time-traces/public/vercel.svg
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
15
packages/next/test/fixtures/00-build-time-traces/vercel.json
vendored
Normal file
15
packages/next/test/fixtures/00-build-time-traces/vercel.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"builds": [
|
||||
{
|
||||
"src": "package.json",
|
||||
"use": "@vercel/next"
|
||||
}
|
||||
],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
}
|
||||
]
|
||||
}
|
||||
34
packages/next/test/fixtures/00-fallback-false-preview/.gitignore
vendored
Normal file
34
packages/next/test/fixtures/00-fallback-false-preview/.gitignore
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
194
packages/next/test/fixtures/00-fallback-false-preview/index.test.js
vendored
Normal file
194
packages/next/test/fixtures/00-fallback-false-preview/index.test.js
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
/* eslint-env jest */
|
||||
const path = require('path');
|
||||
const cheerio = require('cheerio');
|
||||
const setCookieParser = require('set-cookie-parser');
|
||||
const { check, deployAndTest } = require('../../utils');
|
||||
const fetch = require('../../../../../test/lib/deployment/fetch-retry');
|
||||
|
||||
async function checkForChange(url, initialValue, fetchOpts) {
|
||||
if (isNaN(initialValue)) {
|
||||
throw new Error(
|
||||
`expected number for initialValue, received ${initialValue}`
|
||||
);
|
||||
}
|
||||
|
||||
return check(async () => {
|
||||
const res = await fetch(url, fetchOpts);
|
||||
const $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
|
||||
if (isNaN(props.random)) {
|
||||
throw new Error(`Invalid random value ${props.random}`);
|
||||
}
|
||||
const newValue = props.random;
|
||||
return initialValue !== newValue ? 'success' : 'fail';
|
||||
}, 'success');
|
||||
}
|
||||
|
||||
const ctx = {};
|
||||
|
||||
describe(`${__dirname.split(path.sep).pop()}`, () => {
|
||||
it('should deploy and pass probe checks', async () => {
|
||||
const info = await deployAndTest(__dirname);
|
||||
Object.assign(ctx, info);
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /blog', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/blog.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
|
||||
const data = await dataRes.json();
|
||||
expect(data.pageProps.blogIndex).toBe(true);
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/blog`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
|
||||
expect(props.blogIndex).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({});
|
||||
expect($('#pathname').text()).toBe('/blog');
|
||||
expect($('#asPath').text()).toBe('/blog');
|
||||
|
||||
await checkForChange(`${ctx.deploymentUrl}/blog`, initialRandom);
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/blog`);
|
||||
expect(res2.status).toBe(200);
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
|
||||
expect(props2.blogIndex).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({});
|
||||
expect($('#pathname').text()).toBe('/blog');
|
||||
expect($('#asPath').text()).toBe('/blog');
|
||||
});
|
||||
|
||||
it('should load content properly from /blog/first', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/blog/first.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
|
||||
const data = await dataRes.json();
|
||||
expect(data.pageProps.blogSlug).toBe(true);
|
||||
expect(data.pageProps.params).toEqual({ slug: 'first' });
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/blog/first`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
|
||||
expect(props.blogSlug).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({ slug: 'first' });
|
||||
expect($('#pathname').text()).toBe('/blog/[slug]');
|
||||
expect($('#asPath').text()).toBe('/blog/first');
|
||||
|
||||
await checkForChange(`${ctx.deploymentUrl}/blog/first`, initialRandom);
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/blog/first`);
|
||||
expect(res2.status).toBe(200);
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
|
||||
expect(props2.blogSlug).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({ slug: 'first' });
|
||||
expect($('#pathname').text()).toBe('/blog/[slug]');
|
||||
expect($('#asPath').text()).toBe('/blog/first');
|
||||
});
|
||||
|
||||
it('should rewrite/404 for fallback: false page without preview mode', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/blog/another.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(404);
|
||||
expect(await dataRes.text()).toContain('This page could not be found');
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/blog/another`);
|
||||
expect(res.status).toBe(200);
|
||||
expect(await res.text()).toContain('blog fallback rewrite');
|
||||
});
|
||||
|
||||
let previewCookie;
|
||||
|
||||
it('should enable preview mode successfully', async () => {
|
||||
const res = await fetch(`${ctx.deploymentUrl}/api/enable`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const cookies = setCookieParser.parse(
|
||||
setCookieParser.splitCookiesString(res.headers.get('set-cookie'))
|
||||
);
|
||||
const bypassCookie = cookies.find(
|
||||
cookie => cookie.name === '__prerender_bypass'
|
||||
);
|
||||
const previewDataCookie = cookies.find(
|
||||
cookie => cookie.name === '__next_preview_data'
|
||||
);
|
||||
|
||||
expect(bypassCookie).toBeDefined();
|
||||
expect(previewDataCookie).toBeDefined();
|
||||
expect(bypassCookie.value.length > 0).toBe(true);
|
||||
expect(previewDataCookie.value.length > 0).toBe(true);
|
||||
|
||||
previewCookie = cookies.reduce((prev, cur) => {
|
||||
return `${prev}${prev ? ';' : ''}${cur.name}=${cur.value}`;
|
||||
}, '');
|
||||
});
|
||||
|
||||
it('should load fallback: false page with preview mode', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/blog/another.json`,
|
||||
{
|
||||
headers: {
|
||||
Cookie: previewCookie,
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
|
||||
const data = await dataRes.json();
|
||||
expect(data.pageProps.blogSlug).toBe(true);
|
||||
expect(data.pageProps.params).toEqual({ slug: 'another' });
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/blog/another`, {
|
||||
headers: {
|
||||
Cookie: previewCookie,
|
||||
},
|
||||
});
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
|
||||
expect(props.blogSlug).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({ slug: 'another' });
|
||||
expect($('#pathname').text()).toBe('/blog/[slug]');
|
||||
expect($('#asPath').text()).toBe('/blog/another');
|
||||
|
||||
await checkForChange(`${ctx.deploymentUrl}/blog/another`, initialRandom, {
|
||||
headers: {
|
||||
Cookie: previewCookie,
|
||||
},
|
||||
});
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/blog/another`, {
|
||||
headers: {
|
||||
Cookie: previewCookie,
|
||||
},
|
||||
});
|
||||
expect(res2.status).toBe(200);
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
|
||||
expect(props2.blogSlug).toBe(true);
|
||||
expect(JSON.parse($('#query').text())).toEqual({ slug: 'another' });
|
||||
expect($('#pathname').text()).toBe('/blog/[slug]');
|
||||
expect($('#asPath').text()).toBe('/blog/another');
|
||||
});
|
||||
});
|
||||
15
packages/next/test/fixtures/00-fallback-false-preview/next.config.js
vendored
Normal file
15
packages/next/test/fixtures/00-fallback-false-preview/next.config.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = {
|
||||
generateBuildId() {
|
||||
return 'testing-build-id';
|
||||
},
|
||||
rewrites() {
|
||||
return {
|
||||
fallback: [
|
||||
{
|
||||
source: '/blog/:path',
|
||||
destination: '/hello.txt',
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
};
|
||||
15
packages/next/test/fixtures/00-fallback-false-preview/package.json
vendored
Normal file
15
packages/next/test/fixtures/00-fallback-false-preview/package.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "revalidate-no-fallback",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2"
|
||||
}
|
||||
}
|
||||
7
packages/next/test/fixtures/00-fallback-false-preview/pages/_app.js
vendored
Normal file
7
packages/next/test/fixtures/00-fallback-false-preview/pages/_app.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import '../styles/globals.css';
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return <Component {...pageProps} />;
|
||||
}
|
||||
|
||||
export default MyApp;
|
||||
6
packages/next/test/fixtures/00-fallback-false-preview/pages/api/disable.js
vendored
Normal file
6
packages/next/test/fixtures/00-fallback-false-preview/pages/api/disable.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default (req, res) => {
|
||||
res.clearPreviewData({});
|
||||
res.send('disabled preview');
|
||||
};
|
||||
6
packages/next/test/fixtures/00-fallback-false-preview/pages/api/enable.js
vendored
Normal file
6
packages/next/test/fixtures/00-fallback-false-preview/pages/api/enable.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default (req, res) => {
|
||||
res.setPreviewData({});
|
||||
res.send('enabled preview');
|
||||
};
|
||||
3
packages/next/test/fixtures/00-fallback-false-preview/pages/blog-fallback.js
vendored
Normal file
3
packages/next/test/fixtures/00-fallback-false-preview/pages/blog-fallback.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function Home() {
|
||||
return 'blog fallback rewrite';
|
||||
}
|
||||
35
packages/next/test/fixtures/00-fallback-false-preview/pages/blog/[slug].js
vendored
Normal file
35
packages/next/test/fixtures/00-fallback-false-preview/pages/blog/[slug].js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="page">blog slug</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="query">{JSON.stringify(router.query)}</p>
|
||||
<p id="pathname">{router.pathname}</p>
|
||||
<p id="asPath">{router.asPath}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function getStaticProps({ params }) {
|
||||
console.log({ blogSlug: true, params });
|
||||
|
||||
return {
|
||||
props: {
|
||||
random: Math.random() + Date.now(),
|
||||
blogSlug: true,
|
||||
params,
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
}
|
||||
|
||||
export function getStaticPaths() {
|
||||
return {
|
||||
paths: ['/blog/first', '/blog/second'],
|
||||
fallback: false,
|
||||
};
|
||||
}
|
||||
27
packages/next/test/fixtures/00-fallback-false-preview/pages/blog/index.js
vendored
Normal file
27
packages/next/test/fixtures/00-fallback-false-preview/pages/blog/index.js
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="page">blog index</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="query">{JSON.stringify(router.query)}</p>
|
||||
<p id="pathname">{router.pathname}</p>
|
||||
<p id="asPath">{router.asPath}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function getStaticProps() {
|
||||
console.log({ blogIndex: true });
|
||||
|
||||
return {
|
||||
props: {
|
||||
random: Math.random() + Date.now(),
|
||||
blogIndex: true,
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
}
|
||||
70
packages/next/test/fixtures/00-fallback-false-preview/pages/index.js
vendored
Normal file
70
packages/next/test/fixtures/00-fallback-false-preview/pages/index.js
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import Head from 'next/head';
|
||||
import Image from 'next/image';
|
||||
import styles from '../styles/Home.module.css';
|
||||
import VercelLogo from '../public/vercel.png';
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Head>
|
||||
<title>Create Next App</title>
|
||||
<meta name="description" content="Generated by create next app" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
|
||||
<main className={styles.main}>
|
||||
<h1 className={styles.title}>
|
||||
Welcome to <a href="https://nextjs.org">Next.js!</a>
|
||||
</h1>
|
||||
|
||||
<p className={styles.description}>
|
||||
Get started by editing{' '}
|
||||
<code className={styles.code}>pages/index.js</code>
|
||||
</p>
|
||||
|
||||
<div className={styles.grid}>
|
||||
<a href="https://nextjs.org/docs" className={styles.card}>
|
||||
<h2>Documentation →</h2>
|
||||
<p>Find in-depth information about Next.js features and API.</p>
|
||||
</a>
|
||||
|
||||
<a href="https://nextjs.org/learn" className={styles.card}>
|
||||
<h2>Learn →</h2>
|
||||
<p>Learn about Next.js in an interactive course with quizzes!</p>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://github.com/vercel/next.js/tree/master/examples"
|
||||
className={styles.card}
|
||||
>
|
||||
<h2>Examples →</h2>
|
||||
<p>Discover and deploy boilerplate example Next.js projects.</p>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
|
||||
className={styles.card}
|
||||
>
|
||||
<h2>Deploy →</h2>
|
||||
<p>
|
||||
Instantly deploy your Next.js site to a public URL with Vercel.
|
||||
</p>
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer className={styles.footer}>
|
||||
<a
|
||||
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Powered by{' '}
|
||||
<span className={styles.logo}>
|
||||
<Image src={VercelLogo} alt="Vercel Logo" width={72} height={16} />
|
||||
</span>
|
||||
</a>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
BIN
packages/next/test/fixtures/00-fallback-false-preview/public/favicon.ico
vendored
Normal file
BIN
packages/next/test/fixtures/00-fallback-false-preview/public/favicon.ico
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
1
packages/next/test/fixtures/00-fallback-false-preview/public/hello.txt
vendored
Normal file
1
packages/next/test/fixtures/00-fallback-false-preview/public/hello.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
blog fallback rewrite
|
||||
BIN
packages/next/test/fixtures/00-fallback-false-preview/public/vercel.png
vendored
Normal file
BIN
packages/next/test/fixtures/00-fallback-false-preview/public/vercel.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
121
packages/next/test/fixtures/00-fallback-false-preview/styles/Home.module.css
vendored
Normal file
121
packages/next/test/fixtures/00-fallback-false-preview/styles/Home.module.css
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
padding: 0 0.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.main {
|
||||
padding: 5rem 0;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.footer {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
border-top: 1px solid #eaeaea;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.footer a {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.title a {
|
||||
color: #0070f3;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.title a:hover,
|
||||
.title a:focus,
|
||||
.title a:active {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin: 0;
|
||||
line-height: 1.15;
|
||||
font-size: 4rem;
|
||||
}
|
||||
|
||||
.title,
|
||||
.description {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.description {
|
||||
line-height: 1.5;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.code {
|
||||
background: #fafafa;
|
||||
border-radius: 5px;
|
||||
padding: 0.75rem;
|
||||
font-size: 1.1rem;
|
||||
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
|
||||
Bitstream Vera Sans Mono, Courier New, monospace;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
max-width: 800px;
|
||||
margin-top: 3rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
margin: 1rem;
|
||||
padding: 1.5rem;
|
||||
text-align: left;
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
border: 1px solid #eaeaea;
|
||||
border-radius: 10px;
|
||||
transition: color 0.15s ease, border-color 0.15s ease;
|
||||
width: 45%;
|
||||
}
|
||||
|
||||
.card:hover,
|
||||
.card:focus,
|
||||
.card:active {
|
||||
color: #0070f3;
|
||||
border-color: #0070f3;
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin: 0 0 1rem 0;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.card p {
|
||||
margin: 0;
|
||||
font-size: 1.25rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 1em;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.grid {
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
16
packages/next/test/fixtures/00-fallback-false-preview/styles/globals.css
vendored
Normal file
16
packages/next/test/fixtures/00-fallback-false-preview/styles/globals.css
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
html,
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
|
||||
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
39
packages/next/test/fixtures/00-fallback-false-preview/vercel.json
vendored
Normal file
39
packages/next/test/fixtures/00-fallback-false-preview/vercel.json
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"builds": [
|
||||
{
|
||||
"src": "package.json",
|
||||
"use": "@vercel/next"
|
||||
}
|
||||
],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": "pages/index.js"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": "pages/index.js"
|
||||
},
|
||||
{
|
||||
"path": "/_next/image?url=%2Fvercel.png&w=256&q=75",
|
||||
"status": 200,
|
||||
"responseHeaders": {
|
||||
"cache-control": "public, max-age=0, must-revalidate"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fvercel.23a2f7d8.png&w=256&q=75",
|
||||
"status": 200,
|
||||
"responseHeaders": {
|
||||
"cache-control": "public,max-age=31536000,immutable"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/blog/test-123",
|
||||
"status": 200,
|
||||
"mustContain": "blog fallback rewrite"
|
||||
}
|
||||
]
|
||||
}
|
||||
8
packages/next/test/fixtures/00-i18n-404-lambda/index.test.js
vendored
Normal file
8
packages/next/test/fixtures/00-i18n-404-lambda/index.test.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
const path = require('path');
|
||||
const { deployAndTest } = require('../../utils');
|
||||
|
||||
describe(`${__dirname.split(path.sep).pop()}`, () => {
|
||||
it('should deploy and pass probe checks', async () => {
|
||||
await deployAndTest(__dirname);
|
||||
});
|
||||
});
|
||||
9
packages/next/test/fixtures/00-i18n-404-lambda/next.config.js
vendored
Normal file
9
packages/next/test/fixtures/00-i18n-404-lambda/next.config.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
generateBuildId() {
|
||||
return 'testing-build-id';
|
||||
},
|
||||
i18n: {
|
||||
locales: ['en', 'fr', 'nl'],
|
||||
defaultLocale: 'en',
|
||||
},
|
||||
};
|
||||
7
packages/next/test/fixtures/00-i18n-404-lambda/package.json
vendored
Normal file
7
packages/next/test/fixtures/00-i18n-404-lambda/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "latest",
|
||||
"react-dom": "latest"
|
||||
}
|
||||
}
|
||||
3
packages/next/test/fixtures/00-i18n-404-lambda/pages/404.js
vendored
Normal file
3
packages/next/test/fixtures/00-i18n-404-lambda/pages/404.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function NotFound() {
|
||||
return 'not found page';
|
||||
}
|
||||
15
packages/next/test/fixtures/00-i18n-404-lambda/pages/_app.js
vendored
Normal file
15
packages/next/test/fixtures/00-i18n-404-lambda/pages/_app.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import App from 'next/app';
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return <Component {...pageProps} />;
|
||||
}
|
||||
|
||||
MyApp.getInitialProps = async appContext => {
|
||||
const appProps = await App.getInitialProps(appContext);
|
||||
|
||||
return {
|
||||
...appProps,
|
||||
};
|
||||
};
|
||||
|
||||
export default MyApp;
|
||||
11
packages/next/test/fixtures/00-i18n-404-lambda/pages/another.js
vendored
Normal file
11
packages/next/test/fixtures/00-i18n-404-lambda/pages/another.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function Another() {
|
||||
return 'another page';
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ locale }) => ({
|
||||
props: {
|
||||
locale,
|
||||
hello: 'world',
|
||||
},
|
||||
revalidate: 1,
|
||||
});
|
||||
6
packages/next/test/fixtures/00-i18n-404-lambda/pages/api/hello.js
vendored
Normal file
6
packages/next/test/fixtures/00-i18n-404-lambda/pages/api/hello.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default (req, res) => {
|
||||
res.statusCode = 200;
|
||||
res.json({ name: 'John Doe' });
|
||||
};
|
||||
11
packages/next/test/fixtures/00-i18n-404-lambda/pages/index.js
vendored
Normal file
11
packages/next/test/fixtures/00-i18n-404-lambda/pages/index.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function Home() {
|
||||
return 'index page';
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ locale }) => ({
|
||||
props: {
|
||||
locale,
|
||||
hello: 'world',
|
||||
gsspData: true,
|
||||
},
|
||||
});
|
||||
53
packages/next/test/fixtures/00-i18n-404-lambda/vercel.json
vendored
Normal file
53
packages/next/test/fixtures/00-i18n-404-lambda/vercel.json
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [{ "src": "package.json", "use": "@vercel/next" }],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "not found page"
|
||||
},
|
||||
{
|
||||
"path": "/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/fr/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "not found page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/fr",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/another",
|
||||
"status": 200,
|
||||
"mustContain": "another page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/another",
|
||||
"status": 200,
|
||||
"mustContain": "another page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/another",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"fr\""
|
||||
}
|
||||
]
|
||||
}
|
||||
8
packages/next/test/fixtures/00-i18n-404-revalidate/index.test.js
vendored
Normal file
8
packages/next/test/fixtures/00-i18n-404-revalidate/index.test.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
const path = require('path');
|
||||
const { deployAndTest } = require('../../utils');
|
||||
|
||||
describe(`${__dirname.split(path.sep).pop()}`, () => {
|
||||
it('should deploy and pass probe checks', async () => {
|
||||
await deployAndTest(__dirname);
|
||||
});
|
||||
});
|
||||
9
packages/next/test/fixtures/00-i18n-404-revalidate/next.config.js
vendored
Normal file
9
packages/next/test/fixtures/00-i18n-404-revalidate/next.config.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
generateBuildId() {
|
||||
return 'testing-build-id';
|
||||
},
|
||||
i18n: {
|
||||
locales: ['en', 'fr', 'nl'],
|
||||
defaultLocale: 'en',
|
||||
},
|
||||
};
|
||||
7
packages/next/test/fixtures/00-i18n-404-revalidate/package.json
vendored
Normal file
7
packages/next/test/fixtures/00-i18n-404-revalidate/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "latest",
|
||||
"react-dom": "latest"
|
||||
}
|
||||
}
|
||||
13
packages/next/test/fixtures/00-i18n-404-revalidate/pages/404.js
vendored
Normal file
13
packages/next/test/fixtures/00-i18n-404-revalidate/pages/404.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export default function NotFound() {
|
||||
return 'not found page';
|
||||
}
|
||||
|
||||
export const getStaticProps = () => {
|
||||
return {
|
||||
props: {
|
||||
random: Math.random() + Date.now(),
|
||||
hello: 'world',
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
};
|
||||
11
packages/next/test/fixtures/00-i18n-404-revalidate/pages/another.js
vendored
Normal file
11
packages/next/test/fixtures/00-i18n-404-revalidate/pages/another.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function Another() {
|
||||
return 'another page';
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ locale }) => ({
|
||||
props: {
|
||||
locale,
|
||||
hello: 'world',
|
||||
},
|
||||
revalidate: 1,
|
||||
});
|
||||
6
packages/next/test/fixtures/00-i18n-404-revalidate/pages/api/hello.js
vendored
Normal file
6
packages/next/test/fixtures/00-i18n-404-revalidate/pages/api/hello.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default (req, res) => {
|
||||
res.statusCode = 200;
|
||||
res.json({ name: 'John Doe' });
|
||||
};
|
||||
11
packages/next/test/fixtures/00-i18n-404-revalidate/pages/index.js
vendored
Normal file
11
packages/next/test/fixtures/00-i18n-404-revalidate/pages/index.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function Home() {
|
||||
return 'index page';
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ locale }) => ({
|
||||
props: {
|
||||
locale,
|
||||
hello: 'world',
|
||||
gsspData: true,
|
||||
},
|
||||
});
|
||||
48
packages/next/test/fixtures/00-i18n-404-revalidate/vercel.json
vendored
Normal file
48
packages/next/test/fixtures/00-i18n-404-revalidate/vercel.json
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [{ "src": "package.json", "use": "@vercel/next" }],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "not found page"
|
||||
},
|
||||
{
|
||||
"path": "/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/fr/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "not found page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/fr",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/another",
|
||||
"status": 200,
|
||||
"mustContain": "another page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/another",
|
||||
"status": 200,
|
||||
"mustContain": "another page"
|
||||
}
|
||||
]
|
||||
}
|
||||
8
packages/next/test/fixtures/00-i18n-basepath/index.test.js
vendored
Normal file
8
packages/next/test/fixtures/00-i18n-basepath/index.test.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
const path = require('path');
|
||||
const { deployAndTest } = require('../../utils');
|
||||
|
||||
describe(`${__dirname.split(path.sep).pop()}`, () => {
|
||||
it('should deploy and pass probe checks', async () => {
|
||||
await deployAndTest(__dirname);
|
||||
});
|
||||
});
|
||||
10
packages/next/test/fixtures/00-i18n-basepath/next.config.js
vendored
Normal file
10
packages/next/test/fixtures/00-i18n-basepath/next.config.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
generateBuildId() {
|
||||
return 'testing-build-id';
|
||||
},
|
||||
basePath: '/docs',
|
||||
i18n: {
|
||||
locales: ['en', 'fr', 'nl'],
|
||||
defaultLocale: 'en',
|
||||
},
|
||||
};
|
||||
7
packages/next/test/fixtures/00-i18n-basepath/package.json
vendored
Normal file
7
packages/next/test/fixtures/00-i18n-basepath/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "latest",
|
||||
"react-dom": "latest"
|
||||
}
|
||||
}
|
||||
3
packages/next/test/fixtures/00-i18n-basepath/pages/404.js
vendored
Normal file
3
packages/next/test/fixtures/00-i18n-basepath/pages/404.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function NotFound() {
|
||||
return 'not found page';
|
||||
}
|
||||
5
packages/next/test/fixtures/00-i18n-basepath/pages/_app.js
vendored
Normal file
5
packages/next/test/fixtures/00-i18n-basepath/pages/_app.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return <Component {...pageProps} />;
|
||||
}
|
||||
|
||||
export default MyApp;
|
||||
11
packages/next/test/fixtures/00-i18n-basepath/pages/another.js
vendored
Normal file
11
packages/next/test/fixtures/00-i18n-basepath/pages/another.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function Another() {
|
||||
return 'another page';
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ locale }) => ({
|
||||
props: {
|
||||
locale,
|
||||
hello: 'world',
|
||||
},
|
||||
revalidate: 1,
|
||||
});
|
||||
3
packages/next/test/fixtures/00-i18n-basepath/pages/api/blog/[slug].js
vendored
Normal file
3
packages/next/test/fixtures/00-i18n-basepath/pages/api/blog/[slug].js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function handler(req, res) {
|
||||
res.json({ slug: req.query.slug });
|
||||
}
|
||||
3
packages/next/test/fixtures/00-i18n-basepath/pages/api/catchall/[...rest].js
vendored
Normal file
3
packages/next/test/fixtures/00-i18n-basepath/pages/api/catchall/[...rest].js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function handler(req, res) {
|
||||
res.json({ rest: req.query.rest.join('/') });
|
||||
}
|
||||
6
packages/next/test/fixtures/00-i18n-basepath/pages/api/hello.js
vendored
Normal file
6
packages/next/test/fixtures/00-i18n-basepath/pages/api/hello.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default (req, res) => {
|
||||
res.statusCode = 200;
|
||||
res.json({ name: 'John Doe' });
|
||||
};
|
||||
3
packages/next/test/fixtures/00-i18n-basepath/pages/hello.js
vendored
Normal file
3
packages/next/test/fixtures/00-i18n-basepath/pages/hello.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function Page() {
|
||||
return 'hello page';
|
||||
}
|
||||
11
packages/next/test/fixtures/00-i18n-basepath/pages/index.js
vendored
Normal file
11
packages/next/test/fixtures/00-i18n-basepath/pages/index.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function Home() {
|
||||
return 'index page';
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ locale }) => ({
|
||||
props: {
|
||||
locale,
|
||||
hello: 'world',
|
||||
gsspData: true,
|
||||
},
|
||||
});
|
||||
89
packages/next/test/fixtures/00-i18n-basepath/vercel.json
vendored
Normal file
89
packages/next/test/fixtures/00-i18n-basepath/vercel.json
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [{ "src": "package.json", "use": "@vercel/next" }],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/docs/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "not found page"
|
||||
},
|
||||
{
|
||||
"path": "/docs/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/docs/fr/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "not found page"
|
||||
},
|
||||
{
|
||||
"path": "/docs/fr/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/docs",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/docs/fr",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/docs/another",
|
||||
"status": 200,
|
||||
"mustContain": "another page"
|
||||
},
|
||||
{
|
||||
"path": "/docs/fr/another",
|
||||
"status": 200,
|
||||
"mustContain": "another page"
|
||||
},
|
||||
{
|
||||
"path": "/docs/fr/another",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/docs/hello",
|
||||
"status": 200,
|
||||
"mustContain": "hello page"
|
||||
},
|
||||
{
|
||||
"path": "/docs/hello",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/docs/fr/hello",
|
||||
"status": 200,
|
||||
"mustContain": "hello page"
|
||||
},
|
||||
{
|
||||
"path": "/docs/fr/hello",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/docs/api/hello",
|
||||
"status": 200,
|
||||
"mustContain": "John Doe"
|
||||
},
|
||||
{
|
||||
"path": "/docs/api/blog/first",
|
||||
"status": 200,
|
||||
"mustContain": "\"slug\":\"first\""
|
||||
},
|
||||
{
|
||||
"path": "/docs/api/catchall/hello/world",
|
||||
"status": 200,
|
||||
"mustContain": "\"rest\":\"hello/world\""
|
||||
}
|
||||
]
|
||||
}
|
||||
8
packages/next/test/fixtures/00-i18n-gssp-latest/index.test.js
vendored
Normal file
8
packages/next/test/fixtures/00-i18n-gssp-latest/index.test.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
const path = require('path');
|
||||
const { deployAndTest } = require('../../utils');
|
||||
|
||||
describe(`${__dirname.split(path.sep).pop()}`, () => {
|
||||
it('should deploy and pass probe checks', async () => {
|
||||
await deployAndTest(__dirname);
|
||||
});
|
||||
});
|
||||
9
packages/next/test/fixtures/00-i18n-gssp-latest/next.config.js
vendored
Normal file
9
packages/next/test/fixtures/00-i18n-gssp-latest/next.config.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
generateBuildId() {
|
||||
return 'testing-build-id';
|
||||
},
|
||||
i18n: {
|
||||
locales: ['en', 'fr', 'nl'],
|
||||
defaultLocale: 'en',
|
||||
},
|
||||
};
|
||||
10
packages/next/test/fixtures/00-i18n-gssp-latest/package.json
vendored
Normal file
10
packages/next/test/fixtures/00-i18n-gssp-latest/package.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "next build"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "latest",
|
||||
"react": "latest",
|
||||
"react-dom": "latest"
|
||||
}
|
||||
}
|
||||
3
packages/next/test/fixtures/00-i18n-gssp-latest/pages/404.js
vendored
Normal file
3
packages/next/test/fixtures/00-i18n-gssp-latest/pages/404.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function NotFound() {
|
||||
return 'not found page';
|
||||
}
|
||||
11
packages/next/test/fixtures/00-i18n-gssp-latest/pages/another.js
vendored
Normal file
11
packages/next/test/fixtures/00-i18n-gssp-latest/pages/another.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function Another() {
|
||||
return 'another page';
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ locale }) => ({
|
||||
props: {
|
||||
locale,
|
||||
hello: 'world',
|
||||
gsspData: true,
|
||||
},
|
||||
});
|
||||
6
packages/next/test/fixtures/00-i18n-gssp-latest/pages/api/hello.js
vendored
Normal file
6
packages/next/test/fixtures/00-i18n-gssp-latest/pages/api/hello.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default (req, res) => {
|
||||
res.statusCode = 200;
|
||||
res.json({ name: 'John Doe' });
|
||||
};
|
||||
11
packages/next/test/fixtures/00-i18n-gssp-latest/pages/index.js
vendored
Normal file
11
packages/next/test/fixtures/00-i18n-gssp-latest/pages/index.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function Home() {
|
||||
return 'index page';
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ locale }) => ({
|
||||
props: {
|
||||
locale,
|
||||
hello: 'world',
|
||||
gsspData: true,
|
||||
},
|
||||
});
|
||||
99
packages/next/test/fixtures/00-i18n-gssp-latest/vercel.json
vendored
Normal file
99
packages/next/test/fixtures/00-i18n-gssp-latest/vercel.json
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [{ "src": "package.json", "use": "@vercel/next" }],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/fr",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/nl",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"nl\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/another",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/fr/another",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/nl/another",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"nl\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/en.json",
|
||||
"status": 200,
|
||||
"mustContain": "gsspData"
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/en.json",
|
||||
"status": 200,
|
||||
"mustContain": "locale\":\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/fr.json",
|
||||
"status": 200,
|
||||
"mustContain": "gsspData"
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/fr.json",
|
||||
"status": 200,
|
||||
"mustContain": "locale\":\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/nl.json",
|
||||
"status": 200,
|
||||
"mustContain": "gsspData"
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/nl.json",
|
||||
"status": 200,
|
||||
"mustContain": "locale\":\"nl\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/en/another.json",
|
||||
"status": 200,
|
||||
"mustContain": "gsspData"
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/en/another.json",
|
||||
"status": 200,
|
||||
"mustContain": "locale\":\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/fr/another.json",
|
||||
"status": 200,
|
||||
"mustContain": "gsspData"
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/fr/another.json",
|
||||
"status": 200,
|
||||
"mustContain": "locale\":\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/nl/another.json",
|
||||
"status": 200,
|
||||
"mustContain": "gsspData"
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/nl/another.json",
|
||||
"status": 200,
|
||||
"mustContain": "locale\":\"nl\""
|
||||
}
|
||||
]
|
||||
}
|
||||
8
packages/next/test/fixtures/00-i18n-gssp/index.test.js
vendored
Normal file
8
packages/next/test/fixtures/00-i18n-gssp/index.test.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
const path = require('path');
|
||||
const { deployAndTest } = require('../../utils');
|
||||
|
||||
describe(`${__dirname.split(path.sep).pop()}`, () => {
|
||||
it('should deploy and pass probe checks', async () => {
|
||||
await deployAndTest(__dirname);
|
||||
});
|
||||
});
|
||||
34
packages/next/test/fixtures/00-i18n-gssp/next.config.js
vendored
Normal file
34
packages/next/test/fixtures/00-i18n-gssp/next.config.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
module.exports = {
|
||||
generateBuildId() {
|
||||
return 'testing-build-id';
|
||||
},
|
||||
i18n: {
|
||||
locales: ['en', 'fr', 'nl'],
|
||||
defaultLocale: 'en',
|
||||
domains: [],
|
||||
},
|
||||
rewrites() {
|
||||
return [
|
||||
{
|
||||
source: '/sitemap.xml',
|
||||
destination: '/api/hello',
|
||||
},
|
||||
{
|
||||
source: '/to-dynamic-api',
|
||||
destination: '/api/blog/second',
|
||||
},
|
||||
{
|
||||
source: '/test-rewrite-params/:someParam',
|
||||
destination: '/api/hello',
|
||||
},
|
||||
{
|
||||
source: '/api/non-existent',
|
||||
destination: '/another',
|
||||
},
|
||||
{
|
||||
source: '/api/also-non-existent',
|
||||
destination: 'https://example.vercel.sh',
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
7
packages/next/test/fixtures/00-i18n-gssp/package.json
vendored
Normal file
7
packages/next/test/fixtures/00-i18n-gssp/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "latest",
|
||||
"react-dom": "latest"
|
||||
}
|
||||
}
|
||||
3
packages/next/test/fixtures/00-i18n-gssp/pages/404.js
vendored
Normal file
3
packages/next/test/fixtures/00-i18n-gssp/pages/404.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function NotFound() {
|
||||
return 'not found page';
|
||||
}
|
||||
11
packages/next/test/fixtures/00-i18n-gssp/pages/another.js
vendored
Normal file
11
packages/next/test/fixtures/00-i18n-gssp/pages/another.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function Another() {
|
||||
return 'another page';
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ locale }) => ({
|
||||
props: {
|
||||
locale,
|
||||
hello: 'world',
|
||||
gsspData: true,
|
||||
},
|
||||
});
|
||||
3
packages/next/test/fixtures/00-i18n-gssp/pages/api/blog/[slug].js
vendored
Normal file
3
packages/next/test/fixtures/00-i18n-gssp/pages/api/blog/[slug].js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default (req, res) => {
|
||||
res.json({ hello: 'world', query: req.query });
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user