mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-12 21:07:46 +00:00
Compare commits
91 Commits
@now/lambd
...
@now/php@0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77d445af71 | ||
|
|
79251ad180 | ||
|
|
a215dc9103 | ||
|
|
ea7d8f0f6c | ||
|
|
2232efc984 | ||
|
|
b64ce0f3c0 | ||
|
|
74233d50ad | ||
|
|
8aebec9fc3 | ||
|
|
54584b7763 | ||
|
|
d163fcbd71 | ||
|
|
04c2996c76 | ||
|
|
2b69b898ed | ||
|
|
846aa11d6a | ||
|
|
a314a74479 | ||
|
|
40f029a72c | ||
|
|
493d8a778f | ||
|
|
cb5dcb658f | ||
|
|
d77287d07b | ||
|
|
61d66bd957 | ||
|
|
ae73df9e3c | ||
|
|
cb09ae5bbf | ||
|
|
a28eeacdaa | ||
|
|
dd9d46d555 | ||
|
|
4472331ee0 | ||
|
|
ac69836b44 | ||
|
|
15949a4ab4 | ||
|
|
697ada9d73 | ||
|
|
cafbe30fa3 | ||
|
|
583ebcc526 | ||
|
|
52d1bd410c | ||
|
|
11d0753bc1 | ||
|
|
538710fe56 | ||
|
|
2828c89e8d | ||
|
|
e40b45a939 | ||
|
|
38ba8a36fc | ||
|
|
0323c505a3 | ||
|
|
17ee07f4f6 | ||
|
|
0a6ada77ac | ||
|
|
4d817dd67d | ||
|
|
9682a7cc0b | ||
|
|
3456f23b3e | ||
|
|
800ca2cb0e | ||
|
|
ba54b4d706 | ||
|
|
e9482d66a9 | ||
|
|
401b669363 | ||
|
|
a2a0ede1f6 | ||
|
|
3c9fcff743 | ||
|
|
e5aa526583 | ||
|
|
822b0ee3de | ||
|
|
d612e46233 | ||
|
|
77ee10cead | ||
|
|
fb2029c464 | ||
|
|
3b15755054 | ||
|
|
4f65cc3aa8 | ||
|
|
9936e35280 | ||
|
|
a04fd242b8 | ||
|
|
17bc6174a9 | ||
|
|
a7c2d9648a | ||
|
|
faa5ea9e21 | ||
|
|
c52f30c898 | ||
|
|
d675edf1dc | ||
|
|
f85c4f496f | ||
|
|
d52d7904c2 | ||
|
|
79232024bd | ||
|
|
660b787bc3 | ||
|
|
2dbf983ddb | ||
|
|
0866ba9391 | ||
|
|
d259a722a0 | ||
|
|
bf77c51f64 | ||
|
|
062b78130c | ||
|
|
fa70bc50cb | ||
|
|
08e22b35d1 | ||
|
|
9d8f3315a1 | ||
|
|
a737a99a9d | ||
|
|
ee92d92c9f | ||
|
|
34d3ebd289 | ||
|
|
785f187e5d | ||
|
|
44449f474e | ||
|
|
f44dae7f39 | ||
|
|
06f973f641 | ||
|
|
47bb47804e | ||
|
|
5df692979a | ||
|
|
cd02d5390f | ||
|
|
c93fd416c4 | ||
|
|
431db7a62d | ||
|
|
6f86c70313 | ||
|
|
0923fc9200 | ||
|
|
787675f462 | ||
|
|
977615720a | ||
|
|
1a4e64cd27 | ||
|
|
c9fc255002 |
19
lerna.json
19
lerna.json
@@ -2,7 +2,24 @@
|
|||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"useWorkspaces": true,
|
"useWorkspaces": true,
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/now-build-utils",
|
||||||
|
"packages/now-node-bridge",
|
||||||
|
"packages/now-php-bridge",
|
||||||
|
"packages/now-bash",
|
||||||
|
"packages/now-cgi",
|
||||||
|
"packages/now-go",
|
||||||
|
"packages/now-html-minifier",
|
||||||
|
"packages/now-lambda",
|
||||||
|
"packages/now-md",
|
||||||
|
"packages/now-mdx-deck",
|
||||||
|
"packages/now-next",
|
||||||
|
"packages/now-node",
|
||||||
|
"packages/now-node-server",
|
||||||
|
"packages/now-optipng",
|
||||||
|
"packages/now-php",
|
||||||
|
"packages/now-python",
|
||||||
|
"packages/now-static-build",
|
||||||
|
"packages/now-wordpress"
|
||||||
],
|
],
|
||||||
"command": {
|
"command": {
|
||||||
"publish": {
|
"publish": {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
"@types/glob": "^7.1.1",
|
"@types/glob": "^7.1.1",
|
||||||
"@types/multistream": "^2.1.1",
|
"@types/multistream": "^2.1.1",
|
||||||
"@types/node": "^10.12.8",
|
"@types/node": "^10.12.8",
|
||||||
|
"async-retry": "1.2.3",
|
||||||
"buffer-replace": "^1.0.0",
|
"buffer-replace": "^1.0.0",
|
||||||
"eslint": "^5.9.0",
|
"eslint": "^5.9.0",
|
||||||
"eslint-config-airbnb-base": "^13.1.0",
|
"eslint-config-airbnb-base": "^13.1.0",
|
||||||
|
|||||||
32
packages/now-bash/.editorconfig
Normal file
32
packages/now-bash/.editorconfig
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
||||||
|
tab_width = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[{*.json,*.json.example,*.gyp,*.yml}]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.py]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
# Ideal settings - some plugins might support these.
|
||||||
|
[*.js]
|
||||||
|
quote_type = single
|
||||||
|
|
||||||
|
[{*.c,*.cc,*.h,*.hh,*.cpp,*.hpp,*.m,*.mm,*.mpp,*.js,*.java,*.go,*.rs,*.php,*.ng,*.jsx,*.ts,*.d,*.cs,*.swift}]
|
||||||
|
curly_bracket_next_line = false
|
||||||
|
spaces_around_operators = true
|
||||||
|
spaces_around_brackets = outside
|
||||||
|
# close enough to 1TB
|
||||||
|
indent_brace_style = K&R
|
||||||
@@ -33,17 +33,8 @@ if declare -f build > /dev/null; then
|
|||||||
build "$@"
|
build "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure the entrypoint defined a `serve` function
|
# Ensure the entrypoint defined a `handler` function
|
||||||
if ! declare -f serve > /dev/null; then
|
if ! declare -f handler > /dev/null; then
|
||||||
echo "ERROR: A \`serve\` function must be defined in \"$ENTRYPOINT\"!" >&2
|
echo "ERROR: A \`handler\` function must be defined in \"$ENTRYPOINT\"!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Show a tree of the final lambda build
|
|
||||||
show_tree() {
|
|
||||||
import "static-binaries@0.0.6"
|
|
||||||
static_binaries tree
|
|
||||||
echo "Final lambda file tree:"
|
|
||||||
tree -a .
|
|
||||||
}
|
|
||||||
IMPORT_DEBUG= IMPORT_CACHE="$(mktemp -d)" show_tree
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ exports.build = async ({ files, entrypoint, config }) => {
|
|||||||
await execa(builderPath, [entrypoint], {
|
await execa(builderPath, [entrypoint], {
|
||||||
env,
|
env,
|
||||||
cwd: workDir,
|
cwd: workDir,
|
||||||
|
stdio: 'inherit',
|
||||||
});
|
});
|
||||||
|
|
||||||
const lambda = await createLambda({
|
const lambda = await createLambda({
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/bash",
|
"name": "@now/bash",
|
||||||
"version": "0.0.3",
|
"version": "0.1.1",
|
||||||
"description": "Now 2.0 builder for HTTP endpoints written in Bash",
|
"description": "Now 2.0 builder for HTTP endpoints written in Bash",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "Nathan Rajlich <nate@zeit.co>",
|
"author": "Nathan Rajlich <nate@zeit.co>",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import "static-binaries@0.0.6"
|
import "static-binaries@1.0.0"
|
||||||
static_binaries jq
|
static_binaries jq
|
||||||
|
|
||||||
# These get reset upon each request
|
# These get reset upon each request
|
||||||
@@ -35,11 +35,10 @@ _lambda_runtime_next() {
|
|||||||
# Get an event
|
# Get an event
|
||||||
local event
|
local event
|
||||||
event="$(mktemp)"
|
event="$(mktemp)"
|
||||||
_lambda_runtime_api invocation/next -D "$headers" | jq -r '.body' > "$event"
|
_lambda_runtime_api invocation/next -D "$headers" | jq --raw-output --monochrome-output '.body' > "$event"
|
||||||
|
|
||||||
local request_id
|
local request_id
|
||||||
request_id="$(grep -Fi Lambda-Runtime-Aws-Request-Id "$headers" | tr -d '[:space:]' | cut -d: -f2)"
|
request_id="$(grep -Fi Lambda-Runtime-Aws-Request-Id "$headers" | tr -d '[:space:]' | cut -d: -f2)"
|
||||||
echo "Request-Id: $request_id" >&2
|
|
||||||
rm -f "$headers"
|
rm -f "$headers"
|
||||||
|
|
||||||
# Execute the handler function from the script
|
# Execute the handler function from the script
|
||||||
@@ -49,7 +48,7 @@ _lambda_runtime_next() {
|
|||||||
local exit_code=0
|
local exit_code=0
|
||||||
REQUEST="$event"
|
REQUEST="$event"
|
||||||
|
|
||||||
# Stdin of the `serve` function is the HTTP request body.
|
# Stdin of the `handler` function is the HTTP request body.
|
||||||
# Need to use a fifo here instead of bash <() because Lambda
|
# Need to use a fifo here instead of bash <() because Lambda
|
||||||
# errors with "/dev/fd/63 not found" for some reason :/
|
# errors with "/dev/fd/63 not found" for some reason :/
|
||||||
local stdin
|
local stdin
|
||||||
@@ -57,33 +56,30 @@ _lambda_runtime_next() {
|
|||||||
mkfifo "$stdin"
|
mkfifo "$stdin"
|
||||||
_lambda_runtime_body "$event" > "$stdin" &
|
_lambda_runtime_body "$event" > "$stdin" &
|
||||||
|
|
||||||
serve "$event" < "$stdin" > "$body" || exit_code="$?"
|
handler "$event" < "$stdin" > "$body" || exit_code="$?"
|
||||||
rm -f "$event" "$stdin"
|
rm -f "$event" "$stdin"
|
||||||
|
|
||||||
if [ "$exit_code" -eq 0 ]; then
|
if [ "$exit_code" -eq 0 ]; then
|
||||||
# Send the response
|
# Send the response
|
||||||
local response
|
jq --raw-input --raw-output --compact-output --slurp --monochrome-output \
|
||||||
response="$(jq -cnMr \
|
|
||||||
--arg statusCode "$(cat "$_STATUS_CODE")" \
|
--arg statusCode "$(cat "$_STATUS_CODE")" \
|
||||||
--argjson headers "$(cat "$_HEADERS")" \
|
--argjson headers "$(cat "$_HEADERS")" \
|
||||||
--arg body "$(base64 --wrap=0 < "$body")" \
|
'{statusCode:$statusCode|tonumber, headers:$headers, encoding:"base64", body:.|@base64}' < "$body" \
|
||||||
'{statusCode:$statusCode|tonumber, headers:$headers, encoding:"base64", body:$body}')"
|
| _lambda_runtime_api "invocation/$request_id/response" -X POST -d @- > /dev/null
|
||||||
rm -f "$body" "$_HEADERS"
|
rm -f "$body" "$_HEADERS"
|
||||||
_lambda_runtime_api "invocation/$request_id/response" -X POST -d "$response"
|
|
||||||
else
|
else
|
||||||
local error
|
echo "\`handler\` function return code: $exit_code"
|
||||||
error='{"exitCode":'"$exit_code"'}'
|
_lambda_runtime_api "invocation/$request_id/error" -X POST -d @- > /dev/null <<< '{"exitCode":'"$exit_code"'}'
|
||||||
_lambda_runtime_api "invocation/$request_id/error" -X POST -d "$error"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_lambda_runtime_body() {
|
_lambda_runtime_body() {
|
||||||
if [ "$(jq -r '.body | type' < "$1")" = "string" ]; then
|
if [ "$(jq --raw-output '.body | type' < "$1")" = "string" ]; then
|
||||||
if [ "$(jq -r '.encoding' < "$1")" = "base64" ]; then
|
if [ "$(jq --raw-output '.encoding' < "$1")" = "base64" ]; then
|
||||||
jq -r '.body' < "$1" | base64 -d
|
jq --raw-output '.body' < "$1" | base64 -d
|
||||||
else
|
else
|
||||||
# assume plain-text body
|
# assume plain-text body
|
||||||
jq -r '.body' < "$1"
|
jq --raw-output '.body' < "$1"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class FileRef {
|
|||||||
const resp = await fetch(url);
|
const resp = await fetch(url);
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
const error = new BailableError(
|
const error = new BailableError(
|
||||||
`${resp.status} ${resp.statusText}`,
|
`download: ${resp.status} ${resp.statusText} for ${url}`,
|
||||||
);
|
);
|
||||||
if (resp.status === 403) error.bail = true;
|
if (resp.status === 403) error.bail = true;
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
33
packages/now-build-utils/fs/bootstrap-yarn.js
vendored
33
packages/now-build-utils/fs/bootstrap-yarn.js
vendored
@@ -14,15 +14,15 @@ const cachePath = spawnSync(yarnPath, ['cache', 'dir'])
|
|||||||
spawnSync(yarnPath, ['cache', 'clean']);
|
spawnSync(yarnPath, ['cache', 'clean']);
|
||||||
const vfs = new MemoryFileSystem();
|
const vfs = new MemoryFileSystem();
|
||||||
|
|
||||||
function isOutsideCachePath(filename) {
|
function isInsideCachePath(filename) {
|
||||||
const relative = path.relative(cachePath, filename);
|
const relative = path.relative(cachePath, filename);
|
||||||
return relative.startsWith('..');
|
return !relative.startsWith('..');
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveCreateWriteStream = fs.createWriteStream;
|
const saveCreateWriteStream = fs.createWriteStream;
|
||||||
fs.createWriteStream = (...args) => {
|
fs.createWriteStream = (...args) => {
|
||||||
const filename = args[0];
|
const filename = args[0];
|
||||||
if (isOutsideCachePath(filename)) {
|
if (!isInsideCachePath(filename)) {
|
||||||
return saveCreateWriteStream.call(fs, ...args);
|
return saveCreateWriteStream.call(fs, ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ fs.createWriteStream = (...args) => {
|
|||||||
const saveReadFile = fs.readFile;
|
const saveReadFile = fs.readFile;
|
||||||
fs.readFile = (...args) => {
|
fs.readFile = (...args) => {
|
||||||
const filename = args[0];
|
const filename = args[0];
|
||||||
if (isOutsideCachePath(filename)) {
|
if (!isInsideCachePath(filename)) {
|
||||||
return saveReadFile.call(fs, ...args);
|
return saveReadFile.call(fs, ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,23 +60,34 @@ fs.readFile = (...args) => {
|
|||||||
const saveCopyFile = fs.copyFile;
|
const saveCopyFile = fs.copyFile;
|
||||||
fs.copyFile = (...args) => {
|
fs.copyFile = (...args) => {
|
||||||
const src = args[0];
|
const src = args[0];
|
||||||
if (isOutsideCachePath(src)) {
|
|
||||||
return saveCopyFile.call(fs, ...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
const dest = args[1];
|
const dest = args[1];
|
||||||
const callback = args[args.length - 1];
|
const callback = args[args.length - 1];
|
||||||
const buffer = vfs.readFileSync(src);
|
|
||||||
return fs.writeFile(dest, buffer, callback);
|
if (isInsideCachePath(src) && !isInsideCachePath(dest)) {
|
||||||
|
const buffer = vfs.readFileSync(src);
|
||||||
|
return fs.writeFile(dest, buffer, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isInsideCachePath(src) && isInsideCachePath(dest)) {
|
||||||
|
const buffer = fs.readFileSync(src);
|
||||||
|
|
||||||
|
vfs.mkdirpSync(path.dirname(dest));
|
||||||
|
fs.writeFileSync(dest, Buffer.alloc(0));
|
||||||
|
return vfs.writeFile(dest, buffer, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
return saveCopyFile.call(fs, ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveWriteFile = fs.writeFile;
|
const saveWriteFile = fs.writeFile;
|
||||||
fs.writeFile = (...args) => {
|
fs.writeFile = (...args) => {
|
||||||
const filename = args[0];
|
const filename = args[0];
|
||||||
if (isOutsideCachePath(filename)) {
|
if (!isInsideCachePath(filename)) {
|
||||||
return saveWriteFile.call(fs, ...args);
|
return saveWriteFile.call(fs, ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vfs.mkdirpSync(path.dirname(filename));
|
||||||
|
fs.writeFileSync(filename, Buffer.alloc(0));
|
||||||
return vfs.writeFile(...args);
|
return vfs.writeFile(...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
const dev = !process.env.AWS_EXECUTION_ENV;
|
const prod = process.env.AWS_EXECUTION_ENV || process.env.X_GOOGLE_CODE_LOCATION;
|
||||||
const TMP_PATH = dev ? path.join(process.cwd(), 'tmp') : '/tmp';
|
const TMP_PATH = prod ? '/tmp' : path.join(__dirname, 'tmp');
|
||||||
|
|
||||||
module.exports = async function getWritableDirectory() {
|
module.exports = async function getWritableDirectory() {
|
||||||
const name = Math.floor(Math.random() * 0x7fffffff).toString(16);
|
const name = Math.floor(Math.random() * 0x7fffffff).toString(16);
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ const fs = require('fs-extra');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
|
const prod = process.env.AWS_EXECUTION_ENV
|
||||||
|
|| process.env.X_GOOGLE_CODE_LOCATION;
|
||||||
|
|
||||||
function spawnAsync(command, args, cwd) {
|
function spawnAsync(command, args, cwd) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const child = spawn(command, args, { stdio: 'inherit', cwd });
|
const child = spawn(command, args, { stdio: 'inherit', cwd });
|
||||||
@@ -35,7 +38,7 @@ async function scanParentDirs(destPath, scriptName) {
|
|||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
const packageJson = JSON.parse(await fs.readFile(packageJsonPath));
|
const packageJson = JSON.parse(await fs.readFile(packageJsonPath));
|
||||||
hasScript = Boolean(
|
hasScript = Boolean(
|
||||||
packageJson.scripts && packageJson.scripts[scriptName],
|
packageJson.scripts && scriptName && packageJson.scripts[scriptName],
|
||||||
);
|
);
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
hasPackageLockJson = await fs.exists(
|
hasPackageLockJson = await fs.exists(
|
||||||
@@ -52,7 +55,7 @@ async function scanParentDirs(destPath, scriptName) {
|
|||||||
return { hasScript, hasPackageLockJson };
|
return { hasScript, hasPackageLockJson };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runNpmInstall(destPath, args = []) {
|
async function installDependencies(destPath, args = []) {
|
||||||
assert(path.isAbsolute(destPath));
|
assert(path.isAbsolute(destPath));
|
||||||
|
|
||||||
let commandArgs = args;
|
let commandArgs = args;
|
||||||
@@ -63,7 +66,7 @@ async function runNpmInstall(destPath, args = []) {
|
|||||||
commandArgs = args.filter(a => a !== '--prefer-offline');
|
commandArgs = args.filter(a => a !== '--prefer-offline');
|
||||||
await spawnAsync('npm', ['install'].concat(commandArgs), destPath);
|
await spawnAsync('npm', ['install'].concat(commandArgs), destPath);
|
||||||
await spawnAsync('npm', ['cache', 'clean', '--force'], destPath);
|
await spawnAsync('npm', ['cache', 'clean', '--force'], destPath);
|
||||||
} else if (process.env.AWS_EXECUTION_ENV) {
|
} else if (prod) {
|
||||||
console.log('using memory-fs for yarn cache');
|
console.log('using memory-fs for yarn cache');
|
||||||
await spawnAsync(
|
await spawnAsync(
|
||||||
'node',
|
'node',
|
||||||
@@ -99,6 +102,7 @@ async function runPackageJsonScript(destPath, scriptName) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
runShellScript,
|
runShellScript,
|
||||||
runNpmInstall,
|
installDependencies,
|
||||||
|
runNpmInstall: installDependencies,
|
||||||
runPackageJsonScript,
|
runPackageJsonScript,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const Sema = require('async-sema');
|
||||||
const { ZipFile } = require('yazl');
|
const { ZipFile } = require('yazl');
|
||||||
const streamToBuffer = require('./fs/stream-to-buffer.js');
|
const streamToBuffer = require('./fs/stream-to-buffer.js');
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ class Lambda {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sema = new Sema(10);
|
||||||
const mtime = new Date(1540000000000);
|
const mtime = new Date(1540000000000);
|
||||||
|
|
||||||
async function createLambda({
|
async function createLambda({
|
||||||
@@ -23,24 +25,33 @@ async function createLambda({
|
|||||||
assert(typeof handler === 'string', '"handler" is not a string');
|
assert(typeof handler === 'string', '"handler" is not a string');
|
||||||
assert(typeof runtime === 'string', '"runtime" is not a string');
|
assert(typeof runtime === 'string', '"runtime" is not a string');
|
||||||
assert(typeof environment === 'object', '"environment" is not an object');
|
assert(typeof environment === 'object', '"environment" is not an object');
|
||||||
const zipFile = new ZipFile();
|
|
||||||
|
|
||||||
Object.keys(files)
|
await sema.acquire();
|
||||||
.sort()
|
try {
|
||||||
.forEach((name) => {
|
const zipFile = new ZipFile();
|
||||||
const file = files[name];
|
const zipBuffer = await new Promise((resolve, reject) => {
|
||||||
const stream = file.toStream();
|
Object.keys(files)
|
||||||
zipFile.addReadStream(stream, name, { mode: file.mode, mtime });
|
.sort()
|
||||||
|
.forEach((name) => {
|
||||||
|
const file = files[name];
|
||||||
|
const stream = file.toStream();
|
||||||
|
stream.on('error', reject);
|
||||||
|
zipFile.addReadStream(stream, name, { mode: file.mode, mtime });
|
||||||
|
});
|
||||||
|
|
||||||
|
zipFile.end();
|
||||||
|
streamToBuffer(zipFile.outputStream).then(resolve).catch(reject);
|
||||||
});
|
});
|
||||||
|
|
||||||
zipFile.end();
|
return new Lambda({
|
||||||
const zipBuffer = await streamToBuffer(zipFile.outputStream);
|
zipBuffer,
|
||||||
return new Lambda({
|
handler,
|
||||||
zipBuffer,
|
runtime,
|
||||||
handler,
|
environment,
|
||||||
runtime,
|
});
|
||||||
environment,
|
} finally {
|
||||||
});
|
sema.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/build-utils",
|
"name": "@now/build-utils",
|
||||||
"version": "0.4.31",
|
"version": "0.4.32",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async-retry": "1.2.3",
|
"async-retry": "1.2.3",
|
||||||
"async-sema": "2.1.4",
|
"async-sema": "2.1.4",
|
||||||
|
|||||||
5
packages/now-build-utils/test/fixtures/07-cross-install/api/index.js
vendored
Normal file
5
packages/now-build-utils/test/fixtures/07-cross-install/api/index.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const cowsay = require('cowsay').say;
|
||||||
|
|
||||||
|
module.exports = (req, resp) => {
|
||||||
|
resp.end(cowsay({ text: 'cross-cow:RANDOMNESS_PLACEHOLDER' }));
|
||||||
|
};
|
||||||
5
packages/now-build-utils/test/fixtures/07-cross-install/api/package.json
vendored
Normal file
5
packages/now-build-utils/test/fixtures/07-cross-install/api/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"lib": "../lib"
|
||||||
|
}
|
||||||
|
}
|
||||||
7
packages/now-build-utils/test/fixtures/07-cross-install/lib/package.json
vendored
Normal file
7
packages/now-build-utils/test/fixtures/07-cross-install/lib/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"name": "lib",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"dependencies": {
|
||||||
|
"cowsay": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
9
packages/now-build-utils/test/fixtures/07-cross-install/now.json
vendored
Normal file
9
packages/now-build-utils/test/fixtures/07-cross-install/now.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [
|
||||||
|
{ "src": "api/index.js", "use": "@now/node" }
|
||||||
|
],
|
||||||
|
"probes": [
|
||||||
|
{ "path": "/api/index.js", "mustContain": "cross-cow:RANDOMNESS_PLACEHOLDER" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/cgi",
|
"name": "@now/cgi",
|
||||||
"version": "0.0.14",
|
"version": "0.0.15",
|
||||||
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "best -I test/*.js",
|
"test": "best -I test/*.js",
|
||||||
"prepublish": "./build.sh"
|
"prepublish": "./build.sh"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/go",
|
"name": "@now/go",
|
||||||
"version": "0.2.11",
|
"version": "0.2.12",
|
||||||
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "best -I test/*.js",
|
"test": "best -I test/*.js",
|
||||||
"prepublish": "./build.sh"
|
"prepublish": "./build.sh"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/html-minifier",
|
"name": "@now/html-minifier",
|
||||||
"version": "1.0.6",
|
"version": "1.0.7",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"html-minifier": "3.5.21"
|
"html-minifier": "3.5.21"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/lambda",
|
"name": "@now/lambda",
|
||||||
"version": "0.4.8",
|
"version": "0.4.9",
|
||||||
|
"license": "MIT",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@now/build-utils": ">=0.0.1"
|
"@now/build-utils": ">=0.0.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/md",
|
"name": "@now/md",
|
||||||
"version": "0.4.8",
|
"version": "0.4.9",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"rehype-document": "^2.2.0",
|
"rehype-document": "^2.2.0",
|
||||||
"rehype-format": "^2.3.0",
|
"rehype-format": "^2.3.0",
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ const glob = require('@now/build-utils/fs/glob.js');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { runNpmInstall } = require('@now/build-utils/fs/run-user-scripts.js');
|
const { runNpmInstall } = require('@now/build-utils/fs/run-user-scripts.js');
|
||||||
|
|
||||||
exports.analyze = ({ files, entrypoint }) => files[entrypoint].digest;
|
|
||||||
|
|
||||||
const writeFile = promisify(fs.writeFile);
|
const writeFile = promisify(fs.writeFile);
|
||||||
|
|
||||||
exports.build = async ({ files, entrypoint, workPath }) => {
|
exports.build = async ({ files, entrypoint, workPath }) => {
|
||||||
@@ -17,7 +15,7 @@ exports.build = async ({ files, entrypoint, workPath }) => {
|
|||||||
const packageJson = { dependencies: { 'mdx-deck': '1.7.15' } };
|
const packageJson = { dependencies: { 'mdx-deck': '1.7.15' } };
|
||||||
const packageJsonPath = path.join(workPath, 'package.json');
|
const packageJsonPath = path.join(workPath, 'package.json');
|
||||||
await writeFile(packageJsonPath, JSON.stringify(packageJson));
|
await writeFile(packageJsonPath, JSON.stringify(packageJson));
|
||||||
console.log('running npm install...');
|
console.log('installing dependencies...');
|
||||||
process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = '1'; // TODO opts argument for runNpmInstall
|
process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = '1'; // TODO opts argument for runNpmInstall
|
||||||
await runNpmInstall(path.dirname(packageJsonPath), [
|
await runNpmInstall(path.dirname(packageJsonPath), [
|
||||||
'--prod',
|
'--prod',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/mdx-deck",
|
"name": "@now/mdx-deck",
|
||||||
"version": "0.4.17",
|
"version": "0.4.18",
|
||||||
|
"license": "MIT",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@now/build-utils": ">=0.0.1"
|
"@now/build-utils": ">=0.0.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ const {
|
|||||||
runPackageJsonScript,
|
runPackageJsonScript,
|
||||||
} = require('@now/build-utils/fs/run-user-scripts.js');
|
} = require('@now/build-utils/fs/run-user-scripts.js');
|
||||||
const glob = require('@now/build-utils/fs/glob.js');
|
const glob = require('@now/build-utils/fs/glob.js');
|
||||||
|
const semver = require('semver');
|
||||||
|
const nextLegacyVersions = require('./legacy-versions');
|
||||||
const {
|
const {
|
||||||
excludeFiles,
|
excludeFiles,
|
||||||
validateEntrypoint,
|
validateEntrypoint,
|
||||||
includeOnlyEntryDirectory,
|
includeOnlyEntryDirectory,
|
||||||
moveEntryDirectoryToRoot,
|
moveEntryDirectoryToRoot,
|
||||||
excludeLockFiles,
|
|
||||||
normalizePackageJson,
|
normalizePackageJson,
|
||||||
excludeStaticDirectory,
|
excludeStaticDirectory,
|
||||||
onlyStaticDirectory,
|
onlyStaticDirectory,
|
||||||
@@ -88,113 +89,226 @@ exports.build = async ({ files, workPath, entrypoint }) => {
|
|||||||
filesOnlyEntryDirectory,
|
filesOnlyEntryDirectory,
|
||||||
entryDirectory,
|
entryDirectory,
|
||||||
);
|
);
|
||||||
const filesWithoutLockfiles = excludeLockFiles(filesWithEntryDirectoryRoot);
|
|
||||||
const filesWithoutStaticDirectory = excludeStaticDirectory(
|
const filesWithoutStaticDirectory = excludeStaticDirectory(
|
||||||
filesWithoutLockfiles,
|
filesWithEntryDirectoryRoot,
|
||||||
);
|
);
|
||||||
const downloadedFiles = await download(filesWithoutStaticDirectory, workPath);
|
const downloadedFiles = await download(filesWithoutStaticDirectory, workPath);
|
||||||
|
|
||||||
console.log('normalizing package.json');
|
const pkg = await readPackageJson(downloadedFiles);
|
||||||
const packageJson = normalizePackageJson(
|
|
||||||
await readPackageJson(downloadedFiles),
|
let nextVersion;
|
||||||
);
|
if (pkg.dependencies && pkg.dependencies.next) {
|
||||||
console.log('normalized package.json result: ', packageJson);
|
nextVersion = pkg.dependencies.next;
|
||||||
await writePackageJson(workPath, packageJson);
|
} else if (pkg.devDependencies && pkg.devDependencies.next) {
|
||||||
|
nextVersion = pkg.devDependencies.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nextVersion) {
|
||||||
|
throw new Error(
|
||||||
|
'No Next.js version could be detected in "package.json". Make sure `"next"` is installed in "dependencies" or "devDependencies"',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isLegacy = (() => {
|
||||||
|
// If version is using the dist-tag instead of a version range
|
||||||
|
if (nextVersion === 'canary' || nextVersion === 'latest') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the version is an exact match with the legacy versions
|
||||||
|
if (nextLegacyVersions.indexOf(nextVersion) !== -1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxSatisfying = semver.maxSatisfying(nextLegacyVersions, nextVersion);
|
||||||
|
// When the version can't be matched with legacy versions, so it must be a newer version
|
||||||
|
if (maxSatisfying === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
})();
|
||||||
|
|
||||||
|
console.log(`MODE: ${isLegacy ? 'legacy' : 'serverless'}`);
|
||||||
|
|
||||||
|
if (isLegacy) {
|
||||||
|
try {
|
||||||
|
await unlink(path.join(workPath, 'yarn.lock'));
|
||||||
|
} catch (err) {
|
||||||
|
console.log('no yarn.lock removed');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await unlink(path.join(workPath, 'package-lock.json'));
|
||||||
|
} catch (err) {
|
||||||
|
console.log('no package-lock.json removed');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn(
|
||||||
|
"WARNING: your application is being deployed in @now/next's legacy mode.",
|
||||||
|
);
|
||||||
|
console.log('normalizing package.json');
|
||||||
|
const packageJson = normalizePackageJson(pkg);
|
||||||
|
console.log('normalized package.json result: ', packageJson);
|
||||||
|
await writePackageJson(workPath, packageJson);
|
||||||
|
} else if (!pkg.scripts || !pkg.scripts['now-build']) {
|
||||||
|
console.warn(
|
||||||
|
'WARNING: "now-build" script not found. Adding \'"now-build": "next build"\' to "package.json" automatically',
|
||||||
|
);
|
||||||
|
pkg.scripts = {
|
||||||
|
'now-build': 'next build',
|
||||||
|
...(pkg.scripts || {}),
|
||||||
|
};
|
||||||
|
console.log('normalized package.json result: ', pkg);
|
||||||
|
await writePackageJson(workPath, pkg);
|
||||||
|
}
|
||||||
|
|
||||||
if (process.env.NPM_AUTH_TOKEN) {
|
if (process.env.NPM_AUTH_TOKEN) {
|
||||||
console.log('found NPM_AUTH_TOKEN in environment, creating .npmrc');
|
console.log('found NPM_AUTH_TOKEN in environment, creating .npmrc');
|
||||||
await writeNpmRc(workPath, process.env.NPM_AUTH_TOKEN);
|
await writeNpmRc(workPath, process.env.NPM_AUTH_TOKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('running npm install...');
|
console.log('installing dependencies...');
|
||||||
await runNpmInstall(workPath, ['--prefer-offline']);
|
await runNpmInstall(workPath, ['--prefer-offline']);
|
||||||
console.log('running user script...');
|
console.log('running user script...');
|
||||||
await runPackageJsonScript(workPath, 'now-build');
|
await runPackageJsonScript(workPath, 'now-build');
|
||||||
console.log('running npm install --production...');
|
|
||||||
await runNpmInstall(workPath, ['--prefer-offline', '--production']);
|
if (isLegacy) {
|
||||||
|
console.log('running npm install --production...');
|
||||||
|
await runNpmInstall(workPath, ['--prefer-offline', '--production']);
|
||||||
|
}
|
||||||
|
|
||||||
if (process.env.NPM_AUTH_TOKEN) {
|
if (process.env.NPM_AUTH_TOKEN) {
|
||||||
await unlink(path.join(workPath, '.npmrc'));
|
await unlink(path.join(workPath, '.npmrc'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const filesAfterBuild = await glob('**', workPath);
|
|
||||||
|
|
||||||
console.log('preparing lambda files...');
|
|
||||||
let buildId;
|
|
||||||
try {
|
|
||||||
buildId = await readFile(path.join(workPath, '.next', 'BUILD_ID'), 'utf8');
|
|
||||||
} catch (err) {
|
|
||||||
console.error(
|
|
||||||
'BUILD_ID not found in ".next". The "package.json" "build" script did not run "next build"',
|
|
||||||
);
|
|
||||||
throw new Error('Missing BUILD_ID');
|
|
||||||
}
|
|
||||||
const dotNextRootFiles = await glob('.next/*', workPath);
|
|
||||||
const dotNextServerRootFiles = await glob('.next/server/*', workPath);
|
|
||||||
const nodeModules = excludeFiles(
|
|
||||||
await glob('node_modules/**', workPath),
|
|
||||||
file => file.startsWith('node_modules/.cache'),
|
|
||||||
);
|
|
||||||
const launcherFiles = {
|
|
||||||
'now__bridge.js': new FileFsRef({ fsPath: require('@now/node-bridge') }),
|
|
||||||
};
|
|
||||||
const nextFiles = {
|
|
||||||
...nodeModules,
|
|
||||||
...dotNextRootFiles,
|
|
||||||
...dotNextServerRootFiles,
|
|
||||||
...launcherFiles,
|
|
||||||
};
|
|
||||||
if (filesAfterBuild['next.config.js']) {
|
|
||||||
nextFiles['next.config.js'] = filesAfterBuild['next.config.js'];
|
|
||||||
}
|
|
||||||
const pages = await glob(
|
|
||||||
'**/*.js',
|
|
||||||
path.join(workPath, '.next', 'server', 'static', buildId, 'pages'),
|
|
||||||
);
|
|
||||||
const launcherPath = path.join(__dirname, 'launcher.js');
|
|
||||||
const launcherData = await readFile(launcherPath, 'utf8');
|
|
||||||
|
|
||||||
const lambdas = {};
|
const lambdas = {};
|
||||||
await Promise.all(
|
|
||||||
Object.keys(pages).map(async (page) => {
|
|
||||||
// These default pages don't have to be handled as they'd always 404
|
|
||||||
if (['_app.js', '_error.js', '_document.js'].includes(page)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pathname = page.replace(/\.js$/, '');
|
if (isLegacy) {
|
||||||
const launcher = launcherData.replace(
|
const filesAfterBuild = await glob('**', workPath);
|
||||||
'PATHNAME_PLACEHOLDER',
|
|
||||||
`/${pathname.replace(/(^|\/)index$/, '')}`,
|
console.log('preparing lambda files...');
|
||||||
|
let buildId;
|
||||||
|
try {
|
||||||
|
buildId = await readFile(
|
||||||
|
path.join(workPath, '.next', 'BUILD_ID'),
|
||||||
|
'utf8',
|
||||||
);
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(
|
||||||
|
'BUILD_ID not found in ".next". The "package.json" "build" script did not run "next build"',
|
||||||
|
);
|
||||||
|
throw new Error('Missing BUILD_ID');
|
||||||
|
}
|
||||||
|
const dotNextRootFiles = await glob('.next/*', workPath);
|
||||||
|
const dotNextServerRootFiles = await glob('.next/server/*', workPath);
|
||||||
|
const nodeModules = excludeFiles(
|
||||||
|
await glob('node_modules/**', workPath),
|
||||||
|
file => file.startsWith('node_modules/.cache'),
|
||||||
|
);
|
||||||
|
const launcherFiles = {
|
||||||
|
'now__bridge.js': new FileFsRef({ fsPath: require('@now/node-bridge') }),
|
||||||
|
};
|
||||||
|
const nextFiles = {
|
||||||
|
...nodeModules,
|
||||||
|
...dotNextRootFiles,
|
||||||
|
...dotNextServerRootFiles,
|
||||||
|
...launcherFiles,
|
||||||
|
};
|
||||||
|
if (filesAfterBuild['next.config.js']) {
|
||||||
|
nextFiles['next.config.js'] = filesAfterBuild['next.config.js'];
|
||||||
|
}
|
||||||
|
const pages = await glob(
|
||||||
|
'**/*.js',
|
||||||
|
path.join(workPath, '.next', 'server', 'static', buildId, 'pages'),
|
||||||
|
);
|
||||||
|
const launcherPath = path.join(__dirname, 'legacy-launcher.js');
|
||||||
|
const launcherData = await readFile(launcherPath, 'utf8');
|
||||||
|
|
||||||
const pageFiles = {
|
await Promise.all(
|
||||||
[`.next/server/static/${buildId}/pages/_document.js`]: filesAfterBuild[
|
Object.keys(pages).map(async (page) => {
|
||||||
`.next/server/static/${buildId}/pages/_document.js`
|
// These default pages don't have to be handled as they'd always 404
|
||||||
],
|
if (['_app.js', '_error.js', '_document.js'].includes(page)) {
|
||||||
[`.next/server/static/${buildId}/pages/_app.js`]: filesAfterBuild[
|
return;
|
||||||
`.next/server/static/${buildId}/pages/_app.js`
|
}
|
||||||
],
|
|
||||||
[`.next/server/static/${buildId}/pages/_error.js`]: filesAfterBuild[
|
|
||||||
`.next/server/static/${buildId}/pages/_error.js`
|
|
||||||
],
|
|
||||||
[`.next/server/static/${buildId}/pages/${page}`]: filesAfterBuild[
|
|
||||||
`.next/server/static/${buildId}/pages/${page}`
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log(`Creating lambda for page: "${page}"...`);
|
const pathname = page.replace(/\.js$/, '');
|
||||||
lambdas[path.join(entryDirectory, pathname)] = await createLambda({
|
const launcher = launcherData.replace(
|
||||||
files: {
|
'PATHNAME_PLACEHOLDER',
|
||||||
...nextFiles,
|
`/${pathname.replace(/(^|\/)index$/, '')}`,
|
||||||
...pageFiles,
|
);
|
||||||
'now__launcher.js': new FileBlob({ data: launcher }),
|
|
||||||
},
|
const pageFiles = {
|
||||||
handler: 'now__launcher.launcher',
|
[`.next/server/static/${buildId}/pages/_document.js`]: filesAfterBuild[
|
||||||
runtime: 'nodejs8.10',
|
`.next/server/static/${buildId}/pages/_document.js`
|
||||||
});
|
],
|
||||||
console.log(`Created lambda for page: "${page}"`);
|
[`.next/server/static/${buildId}/pages/_app.js`]: filesAfterBuild[
|
||||||
}),
|
`.next/server/static/${buildId}/pages/_app.js`
|
||||||
);
|
],
|
||||||
|
[`.next/server/static/${buildId}/pages/_error.js`]: filesAfterBuild[
|
||||||
|
`.next/server/static/${buildId}/pages/_error.js`
|
||||||
|
],
|
||||||
|
[`.next/server/static/${buildId}/pages/${page}`]: filesAfterBuild[
|
||||||
|
`.next/server/static/${buildId}/pages/${page}`
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(`Creating lambda for page: "${page}"...`);
|
||||||
|
lambdas[path.join(entryDirectory, pathname)] = await createLambda({
|
||||||
|
files: {
|
||||||
|
...nextFiles,
|
||||||
|
...pageFiles,
|
||||||
|
'now__launcher.js': new FileBlob({ data: launcher }),
|
||||||
|
},
|
||||||
|
handler: 'now__launcher.launcher',
|
||||||
|
runtime: 'nodejs8.10',
|
||||||
|
});
|
||||||
|
console.log(`Created lambda for page: "${page}"`);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log('preparing lambda files...');
|
||||||
|
const launcherFiles = {
|
||||||
|
'now__bridge.js': new FileFsRef({ fsPath: require('@now/node-bridge') }),
|
||||||
|
'now__launcher.js': new FileFsRef({
|
||||||
|
fsPath: path.join(__dirname, 'launcher.js'),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
const pages = await glob(
|
||||||
|
'**/*.js',
|
||||||
|
path.join(workPath, '.next', 'serverless', 'pages'),
|
||||||
|
);
|
||||||
|
|
||||||
|
const pageKeys = Object.keys(pages);
|
||||||
|
|
||||||
|
if (pageKeys.length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
'No serverless pages were built. https://err.sh/zeit/now-builders/now-next-no-serverless-pages-built',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
pageKeys.map(async (page) => {
|
||||||
|
// These default pages don't have to be handled as they'd always 404
|
||||||
|
if (['_app.js', '_error.js', '_document.js'].includes(page)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pathname = page.replace(/\.js$/, '');
|
||||||
|
|
||||||
|
console.log(`Creating lambda for page: "${page}"...`);
|
||||||
|
lambdas[path.join(entryDirectory, pathname)] = await createLambda({
|
||||||
|
files: {
|
||||||
|
...launcherFiles,
|
||||||
|
'page.js': pages[page],
|
||||||
|
},
|
||||||
|
handler: 'now__launcher.launcher',
|
||||||
|
runtime: 'nodejs8.10',
|
||||||
|
});
|
||||||
|
console.log(`Created lambda for page: "${page}"`);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const nextStaticFiles = await glob(
|
const nextStaticFiles = await glob(
|
||||||
'**',
|
'**',
|
||||||
@@ -208,7 +322,7 @@ exports.build = async ({ files, workPath, entrypoint }) => {
|
|||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
|
|
||||||
const nextStaticDirectory = onlyStaticDirectory(filesWithoutLockfiles);
|
const nextStaticDirectory = onlyStaticDirectory(filesWithEntryDirectoryRoot);
|
||||||
const staticDirectoryFiles = Object.keys(nextStaticDirectory).reduce(
|
const staticDirectoryFiles = Object.keys(nextStaticDirectory).reduce(
|
||||||
(mappedFiles, file) => ({
|
(mappedFiles, file) => ({
|
||||||
...mappedFiles,
|
...mappedFiles,
|
||||||
@@ -219,41 +333,3 @@ exports.build = async ({ files, workPath, entrypoint }) => {
|
|||||||
|
|
||||||
return { ...lambdas, ...staticFiles, ...staticDirectoryFiles };
|
return { ...lambdas, ...staticFiles, ...staticDirectoryFiles };
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.prepareCache = async ({
|
|
||||||
files, entrypoint, cachePath, workPath,
|
|
||||||
}) => {
|
|
||||||
console.log('downloading user files...');
|
|
||||||
const entryDirectory = path.dirname(entrypoint);
|
|
||||||
const filesOnlyEntryDirectory = includeOnlyEntryDirectory(
|
|
||||||
files,
|
|
||||||
entryDirectory,
|
|
||||||
);
|
|
||||||
const filesWithEntryDirectoryRoot = moveEntryDirectoryToRoot(
|
|
||||||
filesOnlyEntryDirectory,
|
|
||||||
entryDirectory,
|
|
||||||
);
|
|
||||||
const filesWithoutLockfiles = excludeLockFiles(filesWithEntryDirectoryRoot);
|
|
||||||
const filesWithoutStaticDirectory = excludeStaticDirectory(
|
|
||||||
filesWithoutLockfiles,
|
|
||||||
);
|
|
||||||
await download(filesWithoutStaticDirectory, workPath);
|
|
||||||
await download(await glob('.next/**', workPath), cachePath);
|
|
||||||
await download(await glob('node_modules/**', workPath), cachePath);
|
|
||||||
|
|
||||||
console.log('.next folder contents', await glob('.next/**', cachePath));
|
|
||||||
console.log(
|
|
||||||
'.cache folder contents',
|
|
||||||
await glob('node_modules/.cache/**', cachePath),
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log('running npm install...');
|
|
||||||
await runNpmInstall(cachePath);
|
|
||||||
|
|
||||||
return {
|
|
||||||
...(await glob('.next/records.json', cachePath)),
|
|
||||||
...(await glob('.next/server/records.json', cachePath)),
|
|
||||||
...(await glob('node_modules/**', cachePath)),
|
|
||||||
...(await glob('yarn.lock', cachePath)),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,19 +1,13 @@
|
|||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
|
||||||
const { Server } = require('http');
|
const { Server } = require('http');
|
||||||
const next = require('next-server');
|
|
||||||
const url = require('url');
|
|
||||||
const { Bridge } = require('./now__bridge.js');
|
const { Bridge } = require('./now__bridge.js');
|
||||||
|
const page = require('./page.js');
|
||||||
|
|
||||||
const bridge = new Bridge();
|
const bridge = new Bridge();
|
||||||
bridge.port = 3000;
|
bridge.port = 3000;
|
||||||
|
|
||||||
process.env.NODE_ENV = 'production';
|
const server = new Server(page.render);
|
||||||
|
|
||||||
const app = next({});
|
|
||||||
|
|
||||||
const server = new Server((req, res) => {
|
|
||||||
const parsedUrl = url.parse(req.url, true);
|
|
||||||
app.render(req, res, 'PATHNAME_PLACEHOLDER', parsedUrl.query, parsedUrl);
|
|
||||||
});
|
|
||||||
server.listen(bridge.port);
|
server.listen(bridge.port);
|
||||||
|
|
||||||
exports.launcher = bridge.launcher;
|
exports.launcher = bridge.launcher;
|
||||||
|
|||||||
19
packages/now-next/legacy-launcher.js
Normal file
19
packages/now-next/legacy-launcher.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const { Server } = require('http');
|
||||||
|
const next = require('next-server');
|
||||||
|
const url = require('url');
|
||||||
|
const { Bridge } = require('./now__bridge.js');
|
||||||
|
|
||||||
|
const bridge = new Bridge();
|
||||||
|
bridge.port = 3000;
|
||||||
|
|
||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
|
||||||
|
const app = next({});
|
||||||
|
|
||||||
|
const server = new Server((req, res) => {
|
||||||
|
const parsedUrl = url.parse(req.url, true);
|
||||||
|
app.render(req, res, 'PATHNAME_PLACEHOLDER', parsedUrl.query, parsedUrl);
|
||||||
|
});
|
||||||
|
server.listen(bridge.port);
|
||||||
|
|
||||||
|
exports.launcher = bridge.launcher;
|
||||||
336
packages/now-next/legacy-versions.js
Normal file
336
packages/now-next/legacy-versions.js
Normal file
@@ -0,0 +1,336 @@
|
|||||||
|
module.exports = [
|
||||||
|
'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',
|
||||||
|
];
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/next",
|
"name": "@now/next",
|
||||||
"version": "0.0.81",
|
"version": "0.0.84",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@now/node-bridge": "0.1.4",
|
"@now/node-bridge": "0.1.4",
|
||||||
"execa": "^1.0.0",
|
"execa": "^1.0.0",
|
||||||
"fs.promised": "^3.0.0"
|
"fs.promised": "^3.0.0",
|
||||||
|
"semver": "^5.6.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@now/build-utils": ">=0.0.1"
|
"@now/build-utils": ">=0.0.1"
|
||||||
|
|||||||
@@ -153,18 +153,18 @@ function normalizePackageJson(defaultPackageJson = {}) {
|
|||||||
'react-dom': 'latest',
|
'react-dom': 'latest',
|
||||||
...dependencies, // override react if user provided it
|
...dependencies, // override react if user provided it
|
||||||
// next-server is forced to canary
|
// next-server is forced to canary
|
||||||
'next-server': 'canary',
|
'next-server': 'v7.0.2-canary.49',
|
||||||
},
|
},
|
||||||
devDependencies: {
|
devDependencies: {
|
||||||
...devDependencies,
|
...devDependencies,
|
||||||
// next is forced to canary
|
// next is forced to canary
|
||||||
next: 'canary',
|
next: 'v7.0.2-canary.49',
|
||||||
// next-server is a dependency here
|
// next-server is a dependency here
|
||||||
'next-server': undefined,
|
'next-server': undefined,
|
||||||
},
|
},
|
||||||
scripts: {
|
scripts: {
|
||||||
...defaultPackageJson.scripts,
|
...defaultPackageJson.scripts,
|
||||||
'now-build': 'next build --lambdas',
|
'now-build': 'NODE_OPTIONS=--max_old_space_size=3000 next build --lambdas',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
|
||||||
function normalizeEvent(event) {
|
function normalizeEvent(event) {
|
||||||
|
let isApiGateway = true;
|
||||||
|
|
||||||
if (event.Action === 'Invoke') {
|
if (event.Action === 'Invoke') {
|
||||||
|
isApiGateway = false;
|
||||||
const invokeEvent = JSON.parse(event.body);
|
const invokeEvent = JSON.parse(event.body);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -21,10 +24,7 @@ function normalizeEvent(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
method,
|
isApiGateway, method, path, headers, body,
|
||||||
path,
|
|
||||||
headers,
|
|
||||||
body,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,10 +33,7 @@ function normalizeEvent(event) {
|
|||||||
} = event;
|
} = event;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
method,
|
isApiGateway, method, path, headers, body,
|
||||||
path,
|
|
||||||
headers,
|
|
||||||
body,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +55,7 @@ class Bridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
method, path, headers, body,
|
isApiGateway, method, path, headers, body,
|
||||||
} = normalizeEvent(event);
|
} = normalizeEvent(event);
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
@@ -73,20 +70,35 @@ class Bridge {
|
|||||||
const response = res;
|
const response = res;
|
||||||
const respBodyChunks = [];
|
const respBodyChunks = [];
|
||||||
response.on('data', chunk => respBodyChunks.push(Buffer.from(chunk)));
|
response.on('data', chunk => respBodyChunks.push(Buffer.from(chunk)));
|
||||||
response.on('error', error => reject(error));
|
response.on('error', reject);
|
||||||
response.on('end', () => {
|
response.on('end', () => {
|
||||||
|
const bodyBuffer = Buffer.concat(respBodyChunks);
|
||||||
delete response.headers.connection;
|
delete response.headers.connection;
|
||||||
delete response.headers['content-length'];
|
|
||||||
|
if (isApiGateway) {
|
||||||
|
delete response.headers['content-length'];
|
||||||
|
} else
|
||||||
|
if (response.headers['content-length']) {
|
||||||
|
response.headers['content-length'] = bodyBuffer.length;
|
||||||
|
}
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
statusCode: response.statusCode,
|
statusCode: response.statusCode,
|
||||||
headers: response.headers,
|
headers: response.headers,
|
||||||
body: Buffer.concat(respBodyChunks).toString('base64'),
|
body: bodyBuffer.toString('base64'),
|
||||||
encoding: 'base64',
|
encoding: 'base64',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
req.on('error', (error) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
// this lets express print the true error of why the connection was closed.
|
||||||
|
// it is probably 'Cannot set headers after they are sent to the client'
|
||||||
|
reject(error);
|
||||||
|
}, 2);
|
||||||
|
});
|
||||||
|
|
||||||
if (body) req.write(body);
|
if (body) req.write(body);
|
||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/node-bridge",
|
"name": "@now/node-bridge",
|
||||||
"version": "0.1.9",
|
"version": "0.1.10",
|
||||||
|
"license": "MIT",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@now/build-utils": ">=0.0.1"
|
"@now/build-utils": ">=0.0.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ async function downloadInstallAndBundle(
|
|||||||
console.log('downloading user files...');
|
console.log('downloading user files...');
|
||||||
const downloadedFiles = await download(files, userPath);
|
const downloadedFiles = await download(files, userPath);
|
||||||
|
|
||||||
console.log('running npm install for user...');
|
console.log('installing dependencies for user\'s code...');
|
||||||
const entrypointFsDirname = path.join(userPath, path.dirname(entrypoint));
|
const entrypointFsDirname = path.join(userPath, path.dirname(entrypoint));
|
||||||
await runNpmInstall(entrypointFsDirname, npmArguments);
|
await runNpmInstall(entrypointFsDirname, npmArguments);
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ async function downloadInstallAndBundle(
|
|||||||
'package.json': new FileBlob({
|
'package.json': new FileBlob({
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
dependencies: {
|
dependencies: {
|
||||||
'@zeit/ncc': '0.4.1',
|
'@zeit/ncc': '0.11.0',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -55,7 +55,7 @@ async function downloadInstallAndBundle(
|
|||||||
nccPath,
|
nccPath,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('running npm install for ncc...');
|
console.log('installing dependencies for ncc...');
|
||||||
await runNpmInstall(nccPath, npmArguments);
|
await runNpmInstall(nccPath, npmArguments);
|
||||||
return [downloadedFiles, userPath, nccPath, entrypointFsDirname];
|
return [downloadedFiles, userPath, nccPath, entrypointFsDirname];
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,8 @@ async function compile(workNccPath, downloadedFiles, entrypoint) {
|
|||||||
preparedFiles[path.join('user', entrypoint)] = blob;
|
preparedFiles[path.join('user', entrypoint)] = blob;
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
for (const assetName of Object.keys(assets)) {
|
for (const assetName of Object.keys(assets)) {
|
||||||
const blob2 = new FileBlob({ data: assets[assetName] });
|
const { source: data, permissions: mode } = assets[assetName];
|
||||||
|
const blob2 = new FileBlob({ data, mode });
|
||||||
preparedFiles[
|
preparedFiles[
|
||||||
path.join('user', path.dirname(entrypoint), assetName)
|
path.join('user', path.dirname(entrypoint), assetName)
|
||||||
] = blob2;
|
] = blob2;
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ Server.prototype.listen = function listen(...args) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
process.env.NODE_ENV = 'production';
|
if (!process.env.NODE_ENV) {
|
||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
}
|
||||||
|
|
||||||
// PLACEHOLDER
|
// PLACEHOLDER
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/node-server",
|
"name": "@now/node-server",
|
||||||
"version": "0.4.25",
|
"version": "0.4.26",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@now/node-bridge": "^0.1.9",
|
"@now/node-bridge": "^0.1.10",
|
||||||
"fs-extra": "7.0.1"
|
"fs-extra": "7.0.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const cowsay = require('cowsay/build/cowsay.umd.js').say;
|
const cowsay = require('cowsay').say;
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
|
||||||
// test that process.env is not replaced by webpack
|
// test that process.env is not replaced by webpack
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cowsay": "^1.3.1"
|
"cowsay": "1.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const yodasay = require('yodasay/build/yodasay.umd.js').say;
|
const yodasay = require('yodasay').say;
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
|
||||||
// test that process.env is not replaced by webpack
|
// test that process.env is not replaced by webpack
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"yodasay": "^1.1.6"
|
"yodasay": "1.1.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
packages/now-node-server/test/fixtures/06-content-type/index.js
vendored
Normal file
7
packages/now-node-server/test/fixtures/06-content-type/index.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const http = require('http');
|
||||||
|
|
||||||
|
const server = http.createServer((req, resp) => {
|
||||||
|
resp.end('RANDOMNESS_PLACEHOLDER');
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen();
|
||||||
6
packages/now-node-server/test/fixtures/06-content-type/now.json
vendored
Normal file
6
packages/now-node-server/test/fixtures/06-content-type/now.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [
|
||||||
|
{ "src": "index.js", "use": "@now/node-server" }
|
||||||
|
]
|
||||||
|
}
|
||||||
7
packages/now-node-server/test/fixtures/06-content-type/probe.js
vendored
Normal file
7
packages/now-node-server/test/fixtures/06-content-type/probe.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
module.exports = async ({ deploymentUrl, fetch, randomness }) => {
|
||||||
|
const resp = await fetch(`https://${deploymentUrl}/`);
|
||||||
|
assert.equal(resp.headers.get('content-type'), null);
|
||||||
|
assert.equal(await resp.text(), randomness);
|
||||||
|
};
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
{ "src": "without-bundle/index.js", "use": "@now/node-server", "config": { "bundle": false } }
|
{ "src": "without-bundle/index.js", "use": "@now/node-server", "config": { "bundle": false } }
|
||||||
],
|
],
|
||||||
"probes": [
|
"probes": [
|
||||||
{ "path": "/with-bundle", "mustContain": "RANDOMNESS_PLACEHOLDER" },
|
{ "path": "/with-bundle", "mustContain": "RANDOMNESS_PLACEHOLDER:with-bundle" },
|
||||||
{ "path": "/without-bundle", "mustContain": "RANDOMNESS_PLACEHOLDER" }
|
{ "path": "/without-bundle", "mustContain": "RANDOMNESS_PLACEHOLDER:without-bundle" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const http = require('http');
|
|||||||
const isBundled = require('./is-bundled.js');
|
const isBundled = require('./is-bundled.js');
|
||||||
|
|
||||||
const server = http.createServer((req, resp) => {
|
const server = http.createServer((req, resp) => {
|
||||||
resp.end(isBundled() ? 'RANDOMNESS_PLACEHOLDER' : '');
|
resp.end(isBundled() ? 'RANDOMNESS_PLACEHOLDER:with-bundle' : 'WITHOUT-BUNDLE-THAT-IS-WRONG');
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen();
|
server.listen();
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = () => path.basename(__filename) === 'index.js';
|
// eslint-disable-next-line no-eval
|
||||||
|
module.exports = () => path.basename(eval('__filename')) === 'index.js';
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const http = require('http');
|
|||||||
const isBundled = require('./is-bundled.js');
|
const isBundled = require('./is-bundled.js');
|
||||||
|
|
||||||
const server = http.createServer((req, resp) => {
|
const server = http.createServer((req, resp) => {
|
||||||
resp.end(isBundled() ? '' : 'RANDOMNESS_PLACEHOLDER');
|
resp.end(isBundled() ? 'WITH-BUNDLE-THAT-IS-WRONG' : 'RANDOMNESS_PLACEHOLDER:without-bundle');
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen();
|
server.listen();
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = () => path.basename(__filename) === 'index.js';
|
// eslint-disable-next-line no-eval
|
||||||
|
module.exports = () => path.basename(eval('__filename')) === 'index.js';
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ async function downloadInstallAndBundle(
|
|||||||
console.log('downloading user files...');
|
console.log('downloading user files...');
|
||||||
const downloadedFiles = await download(files, userPath);
|
const downloadedFiles = await download(files, userPath);
|
||||||
|
|
||||||
console.log('running npm install for user...');
|
console.log('installing dependencies for user\'s code...');
|
||||||
const entrypointFsDirname = path.join(userPath, path.dirname(entrypoint));
|
const entrypointFsDirname = path.join(userPath, path.dirname(entrypoint));
|
||||||
await runNpmInstall(entrypointFsDirname, npmArguments);
|
await runNpmInstall(entrypointFsDirname, npmArguments);
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ async function downloadInstallAndBundle(
|
|||||||
'package.json': new FileBlob({
|
'package.json': new FileBlob({
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
dependencies: {
|
dependencies: {
|
||||||
'@zeit/ncc': '0.4.1',
|
'@zeit/ncc': '0.11.0',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -53,7 +53,7 @@ async function downloadInstallAndBundle(
|
|||||||
nccPath,
|
nccPath,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('running npm install for ncc...');
|
console.log('installing dependencies for ncc...');
|
||||||
await runNpmInstall(nccPath, npmArguments);
|
await runNpmInstall(nccPath, npmArguments);
|
||||||
return [downloadedFiles, nccPath, entrypointFsDirname];
|
return [downloadedFiles, nccPath, entrypointFsDirname];
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,8 @@ async function compile(workNccPath, downloadedFiles, entrypoint) {
|
|||||||
preparedFiles[path.join('user', entrypoint)] = blob;
|
preparedFiles[path.join('user', entrypoint)] = blob;
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
for (const assetName of Object.keys(assets)) {
|
for (const assetName of Object.keys(assets)) {
|
||||||
const blob2 = new FileBlob({ data: assets[assetName] });
|
const { source: data, permissions: mode } = assets[assetName];
|
||||||
|
const blob2 = new FileBlob({ data, mode });
|
||||||
preparedFiles[
|
preparedFiles[
|
||||||
path.join('user', path.dirname(entrypoint), assetName)
|
path.join('user', path.dirname(entrypoint), assetName)
|
||||||
] = blob2;
|
] = blob2;
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ bridge.port = 3000;
|
|||||||
let listener;
|
let listener;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
process.env.NODE_ENV = 'production';
|
if (!process.env.NODE_ENV) {
|
||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
}
|
||||||
|
|
||||||
// PLACEHOLDER
|
// PLACEHOLDER
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/node",
|
"name": "@now/node",
|
||||||
"version": "0.4.27",
|
"version": "0.4.28",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@now/node-bridge": "^0.1.9",
|
"@now/node-bridge": "^0.1.10",
|
||||||
"fs-extra": "7.0.1"
|
"fs-extra": "7.0.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const cowsay = require('cowsay/build/cowsay.umd.js').say;
|
const cowsay = require('cowsay').say;
|
||||||
|
|
||||||
// test that process.env is not replaced by webpack
|
// test that process.env is not replaced by webpack
|
||||||
process.env.NODE_ENV = 'development';
|
process.env.NODE_ENV = 'development';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cowsay": "^1.3.1"
|
"cowsay": "1.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const yodasay = require('yodasay/build/yodasay.umd.js').say;
|
const yodasay = require('yodasay').say;
|
||||||
|
|
||||||
// test that process.env is not replaced by webpack
|
// test that process.env is not replaced by webpack
|
||||||
process.env.NODE_ENV = 'development';
|
process.env.NODE_ENV = 'development';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"yodasay": "^1.1.6"
|
"yodasay": "1.1.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
packages/now-node/test/fixtures/07-content-length/now.json
vendored
Normal file
8
packages/now-node/test/fixtures/07-content-length/now.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [
|
||||||
|
{ "src": "test1.js", "use": "@now/node" },
|
||||||
|
{ "src": "test2.js", "use": "@now/node" },
|
||||||
|
{ "src": "test3.js", "use": "@now/node" }
|
||||||
|
]
|
||||||
|
}
|
||||||
31
packages/now-node/test/fixtures/07-content-length/probe.js
vendored
Normal file
31
packages/now-node/test/fixtures/07-content-length/probe.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
async function test1({ deploymentUrl, fetch, randomness }) {
|
||||||
|
const bodyMustBe = `${randomness}:content-length`;
|
||||||
|
const resp = await fetch(`https://${deploymentUrl}/test1.js`);
|
||||||
|
assert.equal(resp.status, 401);
|
||||||
|
assert.equal(await resp.text(), bodyMustBe);
|
||||||
|
assert.equal(resp.headers.get('content-length'), bodyMustBe.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function test2({ deploymentUrl, fetch }) {
|
||||||
|
const bodyMustBe = '';
|
||||||
|
const resp = await fetch(`https://${deploymentUrl}/test2.js`);
|
||||||
|
assert.equal(resp.status, 401);
|
||||||
|
assert.equal(await resp.text(), bodyMustBe);
|
||||||
|
assert.equal(resp.headers.get('content-length'), bodyMustBe.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function test3({ deploymentUrl, fetch, randomness }) {
|
||||||
|
const bodyMustBe = `${randomness}:content-length`;
|
||||||
|
const resp = await fetch(`https://${deploymentUrl}/test3.js`);
|
||||||
|
assert.equal(resp.status, 401);
|
||||||
|
assert.equal(await resp.text(), bodyMustBe);
|
||||||
|
assert.equal(resp.headers.get('content-length'), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = async ({ deploymentUrl, fetch, randomness }) => {
|
||||||
|
await test1({ deploymentUrl, fetch, randomness });
|
||||||
|
await test2({ deploymentUrl, fetch, randomness });
|
||||||
|
await test3({ deploymentUrl, fetch, randomness });
|
||||||
|
};
|
||||||
4
packages/now-node/test/fixtures/07-content-length/test1.js
vendored
Normal file
4
packages/now-node/test/fixtures/07-content-length/test1.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = (_, resp) => {
|
||||||
|
resp.writeHead(401, { 'content-length': 4242 });
|
||||||
|
resp.end(`${process.env.RANDOMNESS_ENV_VAR}:content-length`);
|
||||||
|
};
|
||||||
4
packages/now-node/test/fixtures/07-content-length/test2.js
vendored
Normal file
4
packages/now-node/test/fixtures/07-content-length/test2.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = (_, resp) => {
|
||||||
|
resp.writeHead(401, { 'content-length': 2 });
|
||||||
|
resp.end();
|
||||||
|
};
|
||||||
4
packages/now-node/test/fixtures/07-content-length/test3.js
vendored
Normal file
4
packages/now-node/test/fixtures/07-content-length/test3.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = (_, resp) => {
|
||||||
|
resp.writeHead(401);
|
||||||
|
resp.end(`${process.env.RANDOMNESS_ENV_VAR}:content-length`);
|
||||||
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/optipng",
|
"name": "@now/optipng",
|
||||||
"version": "0.4.7",
|
"version": "0.4.8",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"multipipe": "2.0.3",
|
"multipipe": "2.0.3",
|
||||||
"optipng": "1.1.0"
|
"optipng": "1.1.0"
|
||||||
|
|||||||
1
packages/now-php-bridge/.npmignore
Normal file
1
packages/now-php-bridge/.npmignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/build
|
||||||
20
packages/now-php-bridge/build/Dockerfile
Normal file
20
packages/now-php-bridge/build/Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
FROM library/centos:6.8
|
||||||
|
RUN yum -y install wget git
|
||||||
|
RUN rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
|
||||||
|
RUN yum -y install php71w-cli php71w-fpm php71w-mbstring php71w-mysql php71w-opcache
|
||||||
|
RUN yum -y install epel-release
|
||||||
|
RUN yum -y install patchelf
|
||||||
|
|
||||||
|
RUN mkdir -p /root/app/public
|
||||||
|
|
||||||
|
WORKDIR /root/app
|
||||||
|
COPY ./php.ini /root/app/php.ini
|
||||||
|
COPY ./php-fpm.ini /root/app/php-fpm.ini
|
||||||
|
COPY ./test.php /root/app/test.php
|
||||||
|
COPY ./test.sh /root/app/test.sh
|
||||||
|
|
||||||
|
RUN patchelf --set-rpath '$ORIGIN' /usr/bin/php
|
||||||
|
RUN patchelf --set-rpath '$ORIGIN' /usr/sbin/php-fpm
|
||||||
|
RUN patchelf --set-rpath '$ORIGIN' /usr/lib64/php/modules/mysqli.so
|
||||||
|
|
||||||
|
CMD ["/bin/bash", "test.sh"]
|
||||||
15
packages/now-php-bridge/build/build.sh
Executable file
15
packages/now-php-bridge/build/build.sh
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
rm -rf ../native
|
||||||
|
mkdir -p ../native/modules
|
||||||
|
docker rmi now-php-docker-image --force
|
||||||
|
docker build . -t now-php-docker-image
|
||||||
|
docker run now-php-docker-image
|
||||||
|
docker run now-php-docker-image /bin/cat /usr/sbin/php-fpm > ../native/php-fpm
|
||||||
|
docker run now-php-docker-image /bin/cat /root/app/php.ini > ../native/php.ini
|
||||||
|
docker run now-php-docker-image /bin/cat /root/app/php-fpm.ini > ../native/php-fpm.ini
|
||||||
|
docker run now-php-docker-image /bin/cat /usr/lib64/php/modules/curl.so > ../native/modules/curl.so
|
||||||
|
docker run now-php-docker-image /bin/cat /usr/lib64/php/modules/json.so > ../native/modules/json.so
|
||||||
|
docker run now-php-docker-image /bin/cat /usr/lib64/php/modules/mbstring.so > ../native/modules/mbstring.so
|
||||||
|
docker run now-php-docker-image /bin/cat /usr/lib64/php/modules/mysqli.so > ../native/modules/mysqli.so
|
||||||
|
docker run now-php-docker-image /bin/cat /usr/lib64/mysql/libmysqlclient.so.16 > ../native/modules/libmysqlclient.so.16
|
||||||
|
docker run now-php-docker-image /bin/cat /usr/lib64/php/modules/opcache.so > ../native/modules/opcache.so
|
||||||
|
chmod +x ../native/php-fpm
|
||||||
9
packages/now-php-bridge/build/php-fpm.ini
Normal file
9
packages/now-php-bridge/build/php-fpm.ini
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[global]
|
||||||
|
error_log=/tmp/fpm-error.log
|
||||||
|
|
||||||
|
[www]
|
||||||
|
listen=0.0.0.0:9000
|
||||||
|
pm=static
|
||||||
|
pm.max_children=1
|
||||||
|
catch_workers_output=yes
|
||||||
|
clear_env=no
|
||||||
8
packages/now-php-bridge/build/php.ini
Normal file
8
packages/now-php-bridge/build/php.ini
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
extension=/root/app/modules/curl.so
|
||||||
|
extension=/root/app/modules/json.so
|
||||||
|
extension=/root/app/modules/mbstring.so
|
||||||
|
extension=/root/app/modules/mysqli.so
|
||||||
|
zend_extension=/root/app/modules/opcache.so
|
||||||
|
opcache.enable_cli=1
|
||||||
|
mysqli.max_links=10
|
||||||
|
mysqli.max_persistent=10
|
||||||
4
packages/now-php-bridge/build/test.php
Normal file
4
packages/now-php-bridge/build/test.php
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
mysqli_connect();
|
||||||
|
print('php_sapi_name=' . php_sapi_name() . PHP_EOL);
|
||||||
|
print('opcache_enabled=' . opcache_get_status()['opcache_enabled'] . PHP_EOL);
|
||||||
18
packages/now-php-bridge/build/test.sh
Normal file
18
packages/now-php-bridge/build/test.sh
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
mkdir -p /root/app/modules
|
||||||
|
cp /usr/bin/php /root/app/php
|
||||||
|
cp /usr/sbin/php-fpm /root/app/php-fpm
|
||||||
|
cp /usr/lib64/php/modules/curl.so /root/app/modules/curl.so
|
||||||
|
cp /usr/lib64/php/modules/json.so /root/app/modules/json.so
|
||||||
|
cp /usr/lib64/php/modules/mbstring.so /root/app/modules/mbstring.so
|
||||||
|
cp /usr/lib64/php/modules/mysqli.so /root/app/modules/mysqli.so
|
||||||
|
cp /usr/lib64/mysql/libmysqlclient.so.16 /root/app/modules/libmysqlclient.so.16
|
||||||
|
cp /usr/lib64/php/modules/opcache.so /root/app/modules/opcache.so
|
||||||
|
rm -rf $(which php)
|
||||||
|
rm -rf $(which php-fpm)
|
||||||
|
rm -rf /usr/lib64/php
|
||||||
|
rm -rf /usr/lib64/mysql
|
||||||
|
rm -rf /etc/php.d
|
||||||
|
./php-fpm --help
|
||||||
|
./php -c php.ini test.php
|
||||||
|
echo "if you see 'can't connect to local mysql' - it is good - mysql library is found and used"
|
||||||
|
echo "if you see 'call to undefined function mysqli_connect' - it is bad - something went wrong"
|
||||||
149
packages/now-php-bridge/fastcgi/index.js
Normal file
149
packages/now-php-bridge/fastcgi/index.js
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
/* eslint-disable no-bitwise,no-use-before-define */
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const { freeParser } = require('_http_common');
|
||||||
|
const { spawn } = require('child_process');
|
||||||
|
const createConnection = require('./connection.js');
|
||||||
|
const { MSG_TYPE, PROTOCOL_STATUS } = require('./consts.js');
|
||||||
|
const { whenPortOpens } = require('./port.js');
|
||||||
|
|
||||||
|
const { HTTPParser } = process.binding('http_parser');
|
||||||
|
const BEGIN_REQUEST_DATA_KEEP_CONN = Buffer.from('\0\x01\x01\0\0\0\0\0'); // FCGI_ROLE_RESPONDER && FCGI_KEEP_CONN
|
||||||
|
const MESSAGE_FCGI_STDOUT = `message-${MSG_TYPE.FCGI_STDOUT}`;
|
||||||
|
const MESSAGE_FCGI_STDERR = `message-${MSG_TYPE.FCGI_STDERR}`;
|
||||||
|
const MESSAGE_FCGI_END_REQUEST = `message-${MSG_TYPE.FCGI_END_REQUEST}`;
|
||||||
|
|
||||||
|
let curReqId = 0;
|
||||||
|
let connection;
|
||||||
|
|
||||||
|
async function startPhp() {
|
||||||
|
assert(!connection);
|
||||||
|
|
||||||
|
const child = spawn(
|
||||||
|
'./php-fpm',
|
||||||
|
['-c', 'php.ini',
|
||||||
|
'--fpm-config', 'php-fpm.ini',
|
||||||
|
'--nodaemonize'],
|
||||||
|
{
|
||||||
|
stdio: 'inherit',
|
||||||
|
cwd: '/var/task/native',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
child.on('exit', () => {
|
||||||
|
console.error('php exited');
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on('error', (error) => {
|
||||||
|
console.error(error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
await whenPortOpens(9000, 400);
|
||||||
|
|
||||||
|
const newConnection = createConnection({
|
||||||
|
_host: '127.0.0.1',
|
||||||
|
_port: 9000,
|
||||||
|
});
|
||||||
|
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
function onError() {
|
||||||
|
cleanup();
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
function onConnect() {
|
||||||
|
connection = newConnection;
|
||||||
|
cleanup();
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
newConnection.on('error', onError);
|
||||||
|
newConnection.on('connect', onConnect);
|
||||||
|
function cleanup() {
|
||||||
|
newConnection.removeListener('error', onError);
|
||||||
|
newConnection.removeListener('connect', onConnect);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function query({ params, stdin }) {
|
||||||
|
if (!connection) {
|
||||||
|
await startPhp();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
assert(connection);
|
||||||
|
|
||||||
|
const chunks = [
|
||||||
|
Buffer.from('HTTP/1.1 200 MAKES-PARSER-WORK\n'),
|
||||||
|
];
|
||||||
|
|
||||||
|
function onError(error) {
|
||||||
|
console.error(error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
function onStdout(reqId, data) {
|
||||||
|
chunks.push(data);
|
||||||
|
}
|
||||||
|
function onStderr(reqId, data) {
|
||||||
|
console.error(data.toString().trim());
|
||||||
|
}
|
||||||
|
function onEndRequest(reqId, data) {
|
||||||
|
const protocolStatus = data.readUInt8(4, true);
|
||||||
|
if (protocolStatus !== PROTOCOL_STATUS.FCGI_REQUEST_COMPLETE) {
|
||||||
|
console.error('protocolStatus', protocolStatus);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = Buffer.concat(chunks);
|
||||||
|
const parser = new HTTPParser(HTTPParser.RESPONSE);
|
||||||
|
|
||||||
|
let tuples = [];
|
||||||
|
parser[HTTPParser.kOnHeadersComplete | 0] = (major, minor, t) => {
|
||||||
|
tuples = t;
|
||||||
|
};
|
||||||
|
|
||||||
|
let body;
|
||||||
|
parser[HTTPParser.kOnBody | 0] = (b, start, len) => {
|
||||||
|
body = b.slice(start, start + len);
|
||||||
|
};
|
||||||
|
|
||||||
|
parser.execute(response);
|
||||||
|
freeParser(parser);
|
||||||
|
cleanup();
|
||||||
|
resolve({ tuples, body });
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.on('error', onError);
|
||||||
|
connection.on(MESSAGE_FCGI_STDOUT, onStdout);
|
||||||
|
connection.on(MESSAGE_FCGI_STDERR, onStderr);
|
||||||
|
connection.on(MESSAGE_FCGI_END_REQUEST, onEndRequest);
|
||||||
|
function cleanup() {
|
||||||
|
connection.removeListener('error', onError);
|
||||||
|
connection.removeListener(MESSAGE_FCGI_STDOUT, onStdout);
|
||||||
|
connection.removeListener(MESSAGE_FCGI_STDERR, onStderr);
|
||||||
|
connection.removeListener(MESSAGE_FCGI_END_REQUEST, onEndRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
curReqId += 1;
|
||||||
|
// TODO these things have callbacks. what to do with them?
|
||||||
|
connection.send(MSG_TYPE.FCGI_BEGIN_REQUEST, curReqId, BEGIN_REQUEST_DATA_KEEP_CONN);
|
||||||
|
connection.send(MSG_TYPE.FCGI_PARAMS, curReqId, params);
|
||||||
|
connection.send(MSG_TYPE.FCGI_PARAMS, curReqId, null);
|
||||||
|
if (stdin) connection.send(MSG_TYPE.FCGI_STDIN, curReqId, stdin);
|
||||||
|
connection.send(MSG_TYPE.FCGI_STDIN, curReqId, null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
query,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
(async function() {
|
||||||
|
console.log(await query({ params: {
|
||||||
|
REQUEST_METHOD: 'GET', SCRIPT_FILENAME: '/phpinfo.php'
|
||||||
|
} }));
|
||||||
|
})();
|
||||||
|
*/
|
||||||
41
packages/now-php-bridge/fastcgi/port.js
Normal file
41
packages/now-php-bridge/fastcgi/port.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/* eslint-disable consistent-return */
|
||||||
|
|
||||||
|
const net = require('net');
|
||||||
|
|
||||||
|
function whenPortOpensCallback(port, attempts, cb) {
|
||||||
|
const client = net.connect(port, '127.0.0.1');
|
||||||
|
client.on('error', (error) => {
|
||||||
|
if (!attempts) return cb(error);
|
||||||
|
setTimeout(() => {
|
||||||
|
whenPortOpensCallback(port, attempts - 1, cb);
|
||||||
|
}, 50);
|
||||||
|
});
|
||||||
|
client.on('connect', () => {
|
||||||
|
client.destroy();
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPortOpen(port) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
whenPortOpensCallback(port, 0, (error) => {
|
||||||
|
if (error) return resolve(false);
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function whenPortOpens(port, attempts) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
whenPortOpensCallback(port, attempts, (error) => {
|
||||||
|
if (error) return reject(error);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
isPortOpen,
|
||||||
|
whenPortOpensCallback,
|
||||||
|
whenPortOpens,
|
||||||
|
};
|
||||||
28
packages/now-php-bridge/index.js
Normal file
28
packages/now-php-bridge/index.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const FileBlob = require('@now/build-utils/file-blob.js');
|
||||||
|
const FileFsRef = require('@now/build-utils/file-fs-ref.js');
|
||||||
|
const glob = require('@now/build-utils/fs/glob.js');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
async function getFiles() {
|
||||||
|
const files = await glob('native/**', __dirname);
|
||||||
|
|
||||||
|
const phpConfig = await FileBlob.fromStream({ stream: files['native/php.ini'].toStream() });
|
||||||
|
phpConfig.data = phpConfig.data.toString()
|
||||||
|
.replace(/\/root\/app\/modules/g, '/var/task/native/modules');
|
||||||
|
files['native/php.ini'] = phpConfig;
|
||||||
|
|
||||||
|
Object.assign(files, {
|
||||||
|
'fastcgi/connection.js': new FileFsRef({ fsPath: require.resolve('fastcgi-client/lib/connection.js') }),
|
||||||
|
'fastcgi/consts.js': new FileFsRef({ fsPath: require.resolve('fastcgi-client/lib/consts.js') }),
|
||||||
|
'fastcgi/stringifykv.js': new FileFsRef({ fsPath: require.resolve('fastcgi-client/lib/stringifykv.js') }),
|
||||||
|
'fastcgi/index.js': new FileFsRef({ fsPath: path.join(__dirname, 'fastcgi/index.js') }),
|
||||||
|
'fastcgi/port.js': new FileFsRef({ fsPath: path.join(__dirname, 'fastcgi/port.js') }),
|
||||||
|
'launcher.js': new FileFsRef({ fsPath: path.join(__dirname, 'launcher.js') }),
|
||||||
|
});
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getFiles,
|
||||||
|
};
|
||||||
142
packages/now-php-bridge/launcher.js
Normal file
142
packages/now-php-bridge/launcher.js
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
/* eslint-disable prefer-template */
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const fs = require('fs');
|
||||||
|
const { join: pathJoin } = require('path');
|
||||||
|
const { parse: parseUrl } = require('url');
|
||||||
|
const { query } = require('./fastcgi/index.js');
|
||||||
|
|
||||||
|
function normalizeEvent(event) {
|
||||||
|
if (event.Action === 'Invoke') {
|
||||||
|
const invokeEvent = JSON.parse(event.body);
|
||||||
|
|
||||||
|
const {
|
||||||
|
method, path, headers, encoding,
|
||||||
|
} = invokeEvent;
|
||||||
|
|
||||||
|
let { body } = invokeEvent;
|
||||||
|
|
||||||
|
if (body) {
|
||||||
|
if (encoding === 'base64') {
|
||||||
|
body = Buffer.from(body, encoding);
|
||||||
|
} else if (encoding === undefined) {
|
||||||
|
body = Buffer.from(body);
|
||||||
|
} else {
|
||||||
|
throw new Error(`Unsupported encoding: ${encoding}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
method, path, headers, body,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
httpMethod: method, path, headers, body,
|
||||||
|
} = event;
|
||||||
|
|
||||||
|
return {
|
||||||
|
method, path, headers, body,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDirectory(p) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
fs.stat(p, (error, s) => {
|
||||||
|
if (error) {
|
||||||
|
resolve(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s.isDirectory()) {
|
||||||
|
resolve(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function transformFromAwsRequest({
|
||||||
|
method, path, headers, body,
|
||||||
|
}) {
|
||||||
|
const { pathname, search, query: queryString } = parseUrl(path);
|
||||||
|
let requestUri = pathname + (search || '');
|
||||||
|
|
||||||
|
let filename = pathJoin('/var/task/user', pathname);
|
||||||
|
if (await isDirectory(filename)) {
|
||||||
|
if (!filename.endsWith('/')) {
|
||||||
|
filename += '/';
|
||||||
|
requestUri = pathname + '/' + (search || '');
|
||||||
|
}
|
||||||
|
filename += 'index.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
const params = {};
|
||||||
|
params.REQUEST_METHOD = method;
|
||||||
|
params.REQUEST_URI = requestUri;
|
||||||
|
params.QUERY_STRING = queryString || ''; // can be null
|
||||||
|
params.SCRIPT_FILENAME = filename;
|
||||||
|
params.SERVER_PROTOCOL = 'HTTP/1.1';
|
||||||
|
params.SERVER_PORT = 443;
|
||||||
|
params.HTTPS = 'on';
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
|
for (const [k, v] of Object.entries(headers)) {
|
||||||
|
const camel = k.toUpperCase().replace(/-/g, '_');
|
||||||
|
params[`HTTP_${camel}`] = v;
|
||||||
|
if (camel === 'HOST') {
|
||||||
|
params.SERVER_NAME = v;
|
||||||
|
} else
|
||||||
|
if (['CONTENT_TYPE', 'CONTENT_LENGTH'].includes(camel)) {
|
||||||
|
params[camel] = v; // without HOST_ prepended
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { params, stdin: body };
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformToAwsResponse({ tuples, body }) {
|
||||||
|
let statusCode = 200;
|
||||||
|
const headers = {};
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
if (!body) body = Buffer.alloc(0);
|
||||||
|
assert(Buffer.isBuffer(body));
|
||||||
|
|
||||||
|
for (let i = 0; i < tuples.length; i += 2) {
|
||||||
|
const k = tuples[i].toLowerCase();
|
||||||
|
const v = tuples[i + 1];
|
||||||
|
if (k === 'status') {
|
||||||
|
statusCode = Number(v.split(' ')[0]); // '408 Request Timeout'
|
||||||
|
} else {
|
||||||
|
if (!headers[k]) headers[k] = [];
|
||||||
|
headers[k].push(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
statusCode,
|
||||||
|
headers,
|
||||||
|
body: body.toString('base64'),
|
||||||
|
encoding: 'base64',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function launcher(event) {
|
||||||
|
const awsRequest = normalizeEvent(event);
|
||||||
|
const input = await transformFromAwsRequest(awsRequest);
|
||||||
|
const output = await query(input);
|
||||||
|
return transformToAwsResponse(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.launcher = launcher;
|
||||||
|
|
||||||
|
/*
|
||||||
|
(async function() {
|
||||||
|
console.log(await launcher({
|
||||||
|
httpMethod: 'GET',
|
||||||
|
path: '/phpinfo.php'
|
||||||
|
}));
|
||||||
|
})();
|
||||||
|
*/
|
||||||
Binary file not shown.
Binary file not shown.
BIN
packages/now-php-bridge/native/modules/libmysqlclient.so.16
Normal file
BIN
packages/now-php-bridge/native/modules/libmysqlclient.so.16
Normal file
Binary file not shown.
Binary file not shown.
BIN
packages/now-php-bridge/native/modules/mysqli.so
Normal file
BIN
packages/now-php-bridge/native/modules/mysqli.so
Normal file
Binary file not shown.
BIN
packages/now-php-bridge/native/modules/opcache.so
Normal file
BIN
packages/now-php-bridge/native/modules/opcache.so
Normal file
Binary file not shown.
BIN
packages/now-php-bridge/native/php-fpm
Executable file
BIN
packages/now-php-bridge/native/php-fpm
Executable file
Binary file not shown.
9
packages/now-php-bridge/native/php-fpm.ini
Normal file
9
packages/now-php-bridge/native/php-fpm.ini
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[global]
|
||||||
|
error_log=/tmp/fpm-error.log
|
||||||
|
|
||||||
|
[www]
|
||||||
|
listen=0.0.0.0:9000
|
||||||
|
pm=static
|
||||||
|
pm.max_children=1
|
||||||
|
catch_workers_output=yes
|
||||||
|
clear_env=no
|
||||||
8
packages/now-php-bridge/native/php.ini
Normal file
8
packages/now-php-bridge/native/php.ini
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
extension=/root/app/modules/curl.so
|
||||||
|
extension=/root/app/modules/json.so
|
||||||
|
extension=/root/app/modules/mbstring.so
|
||||||
|
extension=/root/app/modules/mysqli.so
|
||||||
|
zend_extension=/root/app/modules/opcache.so
|
||||||
|
opcache.enable_cli=1
|
||||||
|
mysqli.max_links=10
|
||||||
|
mysqli.max_persistent=10
|
||||||
11
packages/now-php-bridge/package.json
Normal file
11
packages/now-php-bridge/package.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "@now/php-bridge",
|
||||||
|
"version": "0.4.13",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"fastcgi-client": "0.0.1"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@now/build-utils": ">=0.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +1 @@
|
|||||||
/launcher
|
|
||||||
/test
|
/test
|
||||||
|
|||||||
BIN
packages/now-php/dist/launcher
vendored
BIN
packages/now-php/dist/launcher
vendored
Binary file not shown.
BIN
packages/now-php/dist/libphp7-7.1.so
vendored
BIN
packages/now-php/dist/libphp7-7.1.so
vendored
Binary file not shown.
3
packages/now-php/dist/php.ini
vendored
3
packages/now-php/dist/php.ini
vendored
@@ -1,3 +0,0 @@
|
|||||||
extension=modules/curl.so
|
|
||||||
extension=modules/json.so
|
|
||||||
extension=modules/mbstring.so
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const { createLambda } = require('@now/build-utils/lambda.js');
|
const { createLambda } = require('@now/build-utils/lambda.js');
|
||||||
const glob = require('@now/build-utils/fs/glob.js');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const rename = require('@now/build-utils/fs/rename.js');
|
const rename = require('@now/build-utils/fs/rename.js');
|
||||||
|
const { getFiles } = require('@now/php-bridge');
|
||||||
|
|
||||||
exports.config = {
|
exports.config = {
|
||||||
maxLambdaSize: '10mb',
|
maxLambdaSize: '10mb',
|
||||||
@@ -10,17 +10,16 @@ exports.config = {
|
|||||||
exports.build = async ({ files, entrypoint }) => {
|
exports.build = async ({ files, entrypoint }) => {
|
||||||
// move all user code to 'user' subdirectory
|
// move all user code to 'user' subdirectory
|
||||||
const userFiles = rename(files, name => path.join('user', name));
|
const userFiles = rename(files, name => path.join('user', name));
|
||||||
const launcherFiles = await glob('**', path.join(__dirname, 'dist'));
|
const bridgeFiles = await getFiles();
|
||||||
const zipFiles = { ...userFiles, ...launcherFiles };
|
|
||||||
|
// TODO config.extensions. OR php.ini from user
|
||||||
|
delete bridgeFiles['native/modules/mysqli.so'];
|
||||||
|
delete bridgeFiles['native/modules/libmysqlclient.so.16'];
|
||||||
|
|
||||||
const lambda = await createLambda({
|
const lambda = await createLambda({
|
||||||
files: zipFiles,
|
files: { ...userFiles, ...bridgeFiles },
|
||||||
handler: 'launcher',
|
handler: 'launcher.launcher',
|
||||||
runtime: 'go1.x',
|
runtime: 'nodejs8.10',
|
||||||
environment: {
|
|
||||||
SCRIPT_NAME: path.join('/', entrypoint),
|
|
||||||
NOW_PHP_SCRIPT: path.join('user', entrypoint),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return { [entrypoint]: lambda };
|
return { [entrypoint]: lambda };
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
FROM library/centos:6.8
|
|
||||||
RUN yum -y install wget git
|
|
||||||
RUN rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
|
|
||||||
RUN yum -y install php71w-cli php71w-devel php71w-embedded php71w-mbstring
|
|
||||||
RUN yum -y install epel-release
|
|
||||||
RUN yum -y install golang
|
|
||||||
|
|
||||||
RUN mkdir -p /root/go/app/public
|
|
||||||
|
|
||||||
RUN go get -v github.com/aws/aws-lambda-go/lambda
|
|
||||||
RUN go get -v github.com/aws/aws-lambda-go/events
|
|
||||||
RUN go get -v github.com/deuill/go-php
|
|
||||||
|
|
||||||
WORKDIR /root/go/app
|
|
||||||
COPY ./utils/bridge.go /root/go/app/utils/bridge.go
|
|
||||||
COPY ./launcher.go /root/go/app/launcher.go
|
|
||||||
COPY ./php.ini /root/go/app/php.ini
|
|
||||||
COPY ./test.go /root/go/app/test.go
|
|
||||||
COPY ./test.php /root/go/app/public/test.php
|
|
||||||
COPY ./test.sh /root/go/app/test.sh
|
|
||||||
|
|
||||||
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o launcher launcher.go
|
|
||||||
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o test test.go
|
|
||||||
|
|
||||||
RUN strip launcher
|
|
||||||
RUN strip test
|
|
||||||
|
|
||||||
CMD ["/bin/bash", "test.sh"]
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
rm -rf ../dist
|
|
||||||
mkdir -p ../dist/modules
|
|
||||||
mkdir ./utils
|
|
||||||
cp ../../../utils/go/bridge/bridge.go ./utils/bridge.go
|
|
||||||
docker rmi go-php-builder --force
|
|
||||||
docker build . -t go-php-builder
|
|
||||||
docker run go-php-builder
|
|
||||||
docker run go-php-builder /bin/cat /root/go/app/launcher > ../dist/launcher
|
|
||||||
docker run go-php-builder /bin/cat /root/go/app/php.ini > ../dist/php.ini
|
|
||||||
docker run go-php-builder /bin/cat /usr/lib64/libphp7-7.1.so > ../dist/libphp7-7.1.so
|
|
||||||
docker run go-php-builder /bin/cat /usr/lib64/php/modules/curl.so > ../dist/modules/curl.so
|
|
||||||
docker run go-php-builder /bin/cat /usr/lib64/php/modules/json.so > ../dist/modules/json.so
|
|
||||||
docker run go-php-builder /bin/cat /usr/lib64/php/modules/mbstring.so > ../dist/modules/mbstring.so
|
|
||||||
chmod +x ../dist/launcher
|
|
||||||
rm -rf ./utils
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
now "./utils"
|
|
||||||
"bytes"
|
|
||||||
php "github.com/deuill/go-php"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PhpHandler struct {
|
|
||||||
http.Handler
|
|
||||||
ScriptFull string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *PhpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
||||||
engine, _ := php.New()
|
|
||||||
context, _ := engine.NewContext()
|
|
||||||
|
|
||||||
var query = r.URL.Query()
|
|
||||||
getMap := make(map[string]string)
|
|
||||||
for k, v := range query {
|
|
||||||
for _, s := range v {
|
|
||||||
getMap[k] = s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
context.Bind("_GET", getMap)
|
|
||||||
|
|
||||||
r.ParseForm()
|
|
||||||
postMap := make(map[string]string)
|
|
||||||
for k, v := range r.PostForm {
|
|
||||||
for _, s := range v {
|
|
||||||
postMap[k] = s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
context.Bind("_POST", postMap)
|
|
||||||
|
|
||||||
envMap := make(map[string]string)
|
|
||||||
for _, e := range os.Environ() {
|
|
||||||
pair := strings.Split(e, "=")
|
|
||||||
envMap[pair[0]] = pair[1]
|
|
||||||
}
|
|
||||||
context.Bind("_ENV", envMap)
|
|
||||||
|
|
||||||
context.Eval("$_SERVER[\"SERVER_NAME\"]=\"" + r.Host + "\";")
|
|
||||||
context.Eval("$_SERVER[\"SERVER_PORT\"]=\"443\";")
|
|
||||||
context.Eval("$_SERVER[\"HTTPS\"]=\"on\";")
|
|
||||||
context.Eval("http_response_code(200);")
|
|
||||||
|
|
||||||
var stdout bytes.Buffer
|
|
||||||
context.Output = &stdout
|
|
||||||
context.Exec(h.ScriptFull)
|
|
||||||
|
|
||||||
statusCodeVal, _ := context.Eval("return http_response_code();")
|
|
||||||
w.WriteHeader(int(statusCodeVal.Int()))
|
|
||||||
|
|
||||||
headers := w.Header()
|
|
||||||
headers.Add("content-type", "text/html")
|
|
||||||
for k, v := range context.Header {
|
|
||||||
for _, s := range v {
|
|
||||||
headers.Add(k, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(stdout.Bytes())
|
|
||||||
|
|
||||||
engine.Destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
ex, _ := os.Executable()
|
|
||||||
handler := &PhpHandler{
|
|
||||||
nil,
|
|
||||||
path.Join(filepath.Dir(ex), os.Getenv("NOW_PHP_SCRIPT")),
|
|
||||||
}
|
|
||||||
now.Start(handler)
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
extension=modules/curl.so
|
|
||||||
extension=modules/json.so
|
|
||||||
extension=modules/mbstring.so
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
php "github.com/deuill/go-php"
|
|
||||||
)
|
|
||||||
|
|
||||||
var public = ""
|
|
||||||
|
|
||||||
func handler() {
|
|
||||||
engine, _ := php.New()
|
|
||||||
context, _ := engine.NewContext()
|
|
||||||
|
|
||||||
var bodyReader = strings.NewReader("Message=from test.go")
|
|
||||||
var httpReq, _ = http.NewRequest("POST", "/dummy/path", bodyReader)
|
|
||||||
httpReq.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
httpReq.ParseForm()
|
|
||||||
|
|
||||||
postMap := make(map[string]string)
|
|
||||||
for k, v := range httpReq.PostForm {
|
|
||||||
for _, s := range v {
|
|
||||||
postMap[k] = s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Bind("_POST", postMap)
|
|
||||||
var stdout bytes.Buffer
|
|
||||||
context.Output = &stdout
|
|
||||||
context.Exec(path.Join(public, "test.php"))
|
|
||||||
|
|
||||||
for k, v := range context.Header {
|
|
||||||
// see https://golang.org/src/net/http/header.go function writeSubset
|
|
||||||
for _, s := range v {
|
|
||||||
fmt.Printf("%s: %s\n", k, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("\n")
|
|
||||||
fmt.Println(stdout.String())
|
|
||||||
engine.Destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
ex, _ := os.Executable()
|
|
||||||
public = path.Join(filepath.Dir(ex), "public")
|
|
||||||
fmt.Printf("public %s\n", path.Join(filepath.Dir(ex), "public"))
|
|
||||||
handler()
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
header('X-See-You: Tomorrow');
|
|
||||||
header('Content-Type: text/html; charset=UTF-8');
|
|
||||||
phpinfo();
|
|
||||||
?>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
ldd launcher
|
|
||||||
# echo Message=hi | REQUEST_METHOD=POST REDIRECT_STATUS=true SCRIPT_FILENAME=index.php CONTENT_LENGTH=10 CONTENT_TYPE=application\/x-www-form-urlencoded php-cgi
|
|
||||||
mkdir -p /root/go/app/modules
|
|
||||||
cp /usr/lib64/php/modules/curl.so /root/go/app/modules/curl.so
|
|
||||||
cp /usr/lib64/php/modules/json.so /root/go/app/modules/json.so
|
|
||||||
cp /usr/lib64/php/modules/mbstring.so /root/go/app/modules/mbstring.so
|
|
||||||
rm -rf /etc/php.d
|
|
||||||
./test | head
|
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/php",
|
"name": "@now/php",
|
||||||
"version": "0.4.12",
|
"version": "0.4.13",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@now/php-bridge": "^0.4.13"
|
||||||
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@now/build-utils": ">=0.0.1"
|
"@now/build-utils": ">=0.0.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
print "cow:RANDOMNESS_PLACEHOLDER";
|
print('cow:RANDOMNESS_PLACEHOLDER');
|
||||||
?>
|
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
print "yoda:RANDOMNESS_PLACEHOLDER";
|
print('yoda:RANDOMNESS_PLACEHOLDER');
|
||||||
?>
|
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
print $_ENV["RANDOMNESS_ENV_VAR"] . ":env";
|
print($_ENV['RANDOMNESS_ENV_VAR'] . ':env');
|
||||||
?>
|
|
||||||
|
|||||||
28
packages/now-php/test/fixtures/11-globals/index.php
vendored
Normal file
28
packages/now-php/test/fixtures/11-globals/index.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: text/plain');
|
||||||
|
print($_SERVER['SCRIPT_FILENAME'] . PHP_EOL);
|
||||||
|
print($_SERVER['REQUEST_METHOD'] . PHP_EOL);
|
||||||
|
print($_SERVER['REQUEST_URI'] . PHP_EOL);
|
||||||
|
print($_SERVER['HTTP_HOST'] . PHP_EOL);
|
||||||
|
print($_SERVER['HTTP_X_SOME_HEADER'] . PHP_EOL);
|
||||||
|
print($_SERVER['SERVER_PROTOCOL'] . PHP_EOL);
|
||||||
|
print($_SERVER['SERVER_NAME'] . PHP_EOL);
|
||||||
|
print($_SERVER['SERVER_PORT'] . PHP_EOL);
|
||||||
|
print($_SERVER['HTTPS'] . PHP_EOL);
|
||||||
|
|
||||||
|
print($_GET['get1'] . PHP_EOL);
|
||||||
|
var_dump($_GET['get2']);
|
||||||
|
print($_POST['post1'] . PHP_EOL);
|
||||||
|
var_dump($_POST['post2']);
|
||||||
|
print($_COOKIE['cookie1'] . PHP_EOL);
|
||||||
|
var_dump($_COOKIE['cookie2']);
|
||||||
|
|
||||||
|
print($_REQUEST['get1'] . PHP_EOL);
|
||||||
|
var_dump($_REQUEST['get2']);
|
||||||
|
print($_REQUEST['post1'] . PHP_EOL);
|
||||||
|
var_dump($_REQUEST['post2']);
|
||||||
|
print($_REQUEST['cookie1'] . PHP_EOL);
|
||||||
|
var_dump($_REQUEST['cookie2']);
|
||||||
|
|
||||||
|
print(file_get_contents('php://input') . PHP_EOL);
|
||||||
|
print('end' . PHP_EOL);
|
||||||
6
packages/now-php/test/fixtures/11-globals/now.json
vendored
Normal file
6
packages/now-php/test/fixtures/11-globals/now.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [
|
||||||
|
{ "src": "index.php", "use": "@now/php" }
|
||||||
|
]
|
||||||
|
}
|
||||||
157
packages/now-php/test/fixtures/11-globals/probe.js
vendored
Normal file
157
packages/now-php/test/fixtures/11-globals/probe.js
vendored
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
async function test1({ deploymentUrl, fetch }) {
|
||||||
|
const resp = await fetch(
|
||||||
|
`https://${deploymentUrl}/index.php?get1=foo&get1=bar&get2[]=bim&get2[]=bom`, {
|
||||||
|
headers: {
|
||||||
|
'X-Some-Header': 'x-some-header-value',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
assert(resp.status === 200);
|
||||||
|
const text = await resp.text();
|
||||||
|
const lines = text.trim().split('\n');
|
||||||
|
|
||||||
|
assert.deepEqual(lines, [
|
||||||
|
'/var/task/user/index.php',
|
||||||
|
'GET',
|
||||||
|
'/index.php?get1=foo&get1=bar&get2%5B%5D=bim&get2%5B%5D=bom', // TODO fake news, must be unescaped
|
||||||
|
deploymentUrl, // example 'test-19phw91ph.now.sh'
|
||||||
|
'x-some-header-value',
|
||||||
|
'HTTP/1.1',
|
||||||
|
deploymentUrl, // example 'test-19phw91ph.now.sh'
|
||||||
|
'443',
|
||||||
|
'on',
|
||||||
|
'bar',
|
||||||
|
'array(2) {',
|
||||||
|
' [0]=>',
|
||||||
|
' string(3) "bim"',
|
||||||
|
' [1]=>',
|
||||||
|
' string(3) "bom"',
|
||||||
|
'}',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'bar',
|
||||||
|
'array(2) {',
|
||||||
|
' [0]=>',
|
||||||
|
' string(3) "bim"',
|
||||||
|
' [1]=>',
|
||||||
|
' string(3) "bom"',
|
||||||
|
'}',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'',
|
||||||
|
'end',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function test2({ deploymentUrl, fetch }) {
|
||||||
|
const resp = await fetch(
|
||||||
|
`https://${deploymentUrl}/index.php`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: 'post1=baz&post1=bat&post2[]=pim&post2[]=pom',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
assert(resp.status === 200);
|
||||||
|
const text = await resp.text();
|
||||||
|
const lines = text.trim().split('\n');
|
||||||
|
|
||||||
|
assert.deepEqual(lines, [
|
||||||
|
'/var/task/user/index.php',
|
||||||
|
'POST',
|
||||||
|
'/index.php',
|
||||||
|
deploymentUrl, // example 'test-19phw91ph.now.sh'
|
||||||
|
'',
|
||||||
|
'HTTP/1.1',
|
||||||
|
deploymentUrl, // example 'test-19phw91ph.now.sh'
|
||||||
|
'443',
|
||||||
|
'on',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'bat',
|
||||||
|
'array(2) {',
|
||||||
|
' [0]=>',
|
||||||
|
' string(3) "pim"',
|
||||||
|
' [1]=>',
|
||||||
|
' string(3) "pom"',
|
||||||
|
'}',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'bat',
|
||||||
|
'array(2) {',
|
||||||
|
' [0]=>',
|
||||||
|
' string(3) "pim"',
|
||||||
|
' [1]=>',
|
||||||
|
' string(3) "pom"',
|
||||||
|
'}',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'post1=baz&post1=bat&post2[]=pim&post2[]=pom',
|
||||||
|
'end',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function test3({ deploymentUrl, fetch }) {
|
||||||
|
const resp = await fetch(
|
||||||
|
`https://${deploymentUrl}/index.php`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Cookie: `cookie1=foo; cookie1=${escape('bar|bar')}; ${escape('cookie2[]')}=dim; ${escape('cookie2[]')}=${escape('dom|dom')}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
assert(resp.status === 200);
|
||||||
|
const text = await resp.text();
|
||||||
|
const lines = text.trim().split('\n');
|
||||||
|
|
||||||
|
assert.deepEqual(lines, [
|
||||||
|
'/var/task/user/index.php',
|
||||||
|
'GET',
|
||||||
|
'/index.php',
|
||||||
|
deploymentUrl, // example 'test-19phw91ph.now.sh'
|
||||||
|
'',
|
||||||
|
'HTTP/1.1',
|
||||||
|
deploymentUrl, // example 'test-19phw91ph.now.sh'
|
||||||
|
'443',
|
||||||
|
'on',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'foo',
|
||||||
|
'array(2) {',
|
||||||
|
' [0]=>',
|
||||||
|
' string(3) "dim"',
|
||||||
|
' [1]=>',
|
||||||
|
' string(7) "dom|dom"',
|
||||||
|
'}',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'',
|
||||||
|
'NULL',
|
||||||
|
'foo',
|
||||||
|
'array(2) {',
|
||||||
|
' [0]=>',
|
||||||
|
' string(3) "dim"',
|
||||||
|
' [1]=>',
|
||||||
|
' string(7) "dom|dom"',
|
||||||
|
'}',
|
||||||
|
'',
|
||||||
|
'end',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = async (opts) => {
|
||||||
|
await test1(opts);
|
||||||
|
await test2(opts);
|
||||||
|
await test3(opts);
|
||||||
|
};
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user