mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-12 04:22:14 +00:00
Compare commits
57 Commits
@now/pytho
...
@now/pytho
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89172a6e89 | ||
|
|
e8f1dbaa46 | ||
|
|
16b5b6fdf3 | ||
|
|
3bab29ff76 | ||
|
|
d675d2e668 | ||
|
|
2dda88e676 | ||
|
|
5a0090eb1f | ||
|
|
d438b4ec4e | ||
|
|
f8810fd7e6 | ||
|
|
a642cfea96 | ||
|
|
2daa20a9f2 | ||
|
|
4d5c0c40f0 | ||
|
|
29051681df | ||
|
|
96d5e81538 | ||
|
|
9ba9dd6949 | ||
|
|
b362d57270 | ||
|
|
4ff95e1718 | ||
|
|
ef02bedd4d | ||
|
|
ed68a09c3e | ||
|
|
ac7ae5fc5d | ||
|
|
9727b1f020 | ||
|
|
2dc454f15f | ||
|
|
4463af5c7a | ||
|
|
c00fb37cf6 | ||
|
|
4deb426f9c | ||
|
|
008b04413a | ||
|
|
f177ba46e9 | ||
|
|
c030fce589 | ||
|
|
50a5150bb5 | ||
|
|
0578ccf47e | ||
|
|
e32cd36ded | ||
|
|
6ac0ab121c | ||
|
|
05db2e6a73 | ||
|
|
0b89d30d6c | ||
|
|
8a021c9417 | ||
|
|
f218771382 | ||
|
|
17309291ed | ||
|
|
86300577ae | ||
|
|
f9594e0d61 | ||
|
|
20fd4b2e12 | ||
|
|
718e4d0e0c | ||
|
|
dc3584cd08 | ||
|
|
b41788b241 | ||
|
|
af9a2f9792 | ||
|
|
f8b8e760de | ||
|
|
93d6ec8024 | ||
|
|
7ed6b84056 | ||
|
|
31da488365 | ||
|
|
8eaf05f782 | ||
|
|
9311e90f27 | ||
|
|
c0de970de2 | ||
|
|
465ac2093d | ||
|
|
19ab0e8698 | ||
|
|
02fa98e5e3 | ||
|
|
4aef9d48b0 | ||
|
|
bd2d05344e | ||
|
|
edc7696623 |
7
.github/CODEOWNERS
vendored
Normal file
7
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Documentation
|
||||||
|
# https://help.github.com/en/articles/about-code-owners
|
||||||
|
|
||||||
|
* @styfle
|
||||||
|
/packages/now-node @styfle @tootallnate
|
||||||
|
/packages/now-next @styfle @dav-is
|
||||||
|
/packages/now-go @styfle @sophearak
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,3 +2,5 @@ node_modules
|
|||||||
tmp
|
tmp
|
||||||
target/
|
target/
|
||||||
.next
|
.next
|
||||||
|
coverage
|
||||||
|
*.tgz
|
||||||
|
|||||||
38
errors/now-static-build-failed-to-detect-a-server.md
Normal file
38
errors/now-static-build-failed-to-detect-a-server.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# `@now/static-build` Failed to detect a server running
|
||||||
|
|
||||||
|
#### Why This Warning Occurred
|
||||||
|
|
||||||
|
When running `now dev`, the `@now/static-build` builder proxies relevant HTTP
|
||||||
|
requests to the server that is created by the `now-dev` script in the
|
||||||
|
`package.json` file.
|
||||||
|
|
||||||
|
In order for `now dev` to know which port the server is running on, the builder
|
||||||
|
is provided a `$PORT` environment variable that the server *must* bind to. The
|
||||||
|
error "Failed to detect a server running on port" is printed if the builder fails
|
||||||
|
to detect a server listening on that specific port within five minutes.
|
||||||
|
|
||||||
|
#### Possible Ways to Fix It
|
||||||
|
|
||||||
|
Please ensure that your `now-dev` script binds the spawned development server on
|
||||||
|
the provided `$PORT` that the builder expects the server to bind to.
|
||||||
|
|
||||||
|
For example, if you are using Gatsby, your `now-dev` script must use the `-p`
|
||||||
|
(port) option to bind to the `$PORT` specified from the builder:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
...
|
||||||
|
"scripts": {
|
||||||
|
...
|
||||||
|
"now-dev": "gatsby develop -p $PORT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Consult your static builder program's `--help` or documentation to figure out what
|
||||||
|
the command line flag to bind to a specific port is (in many cases, it is one of:
|
||||||
|
`-p` / `-P` / `--port`).
|
||||||
|
|
||||||
|
### Useful Links
|
||||||
|
|
||||||
|
- [`@now/static-build` Local Development Documentation](https://zeit.co/docs/v2/deployments/official-builders/static-build-now-static-build#local-development)
|
||||||
@@ -1,5 +1,37 @@
|
|||||||
|
const childProcess = require('child_process');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const command = 'git diff HEAD~1 --name-only';
|
||||||
|
const diff = childProcess.execSync(command).toString();
|
||||||
|
|
||||||
|
const changed = diff
|
||||||
|
.split('\n')
|
||||||
|
.filter(item => Boolean(item) && item.includes('packages/'))
|
||||||
|
.map(item => path.relative('packages', item).split('/')[0]);
|
||||||
|
|
||||||
|
const matches = [];
|
||||||
|
|
||||||
|
if (changed.length > 0) {
|
||||||
|
console.log('The following packages have changed:');
|
||||||
|
|
||||||
|
changed.map((item) => {
|
||||||
|
matches.push(item);
|
||||||
|
console.log(item);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
matches.push('now-node');
|
||||||
|
console.log(`No packages changed, defaulting to ${matches[0]}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const testMatch = Array.from(new Set(matches)).map(
|
||||||
|
item => `**/${item}/**/?(*.)+(spec|test).[jt]s?(x)`,
|
||||||
|
);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
|
testMatch,
|
||||||
collectCoverageFrom: [
|
collectCoverageFrom: [
|
||||||
'packages/(!test)/**/*.{js,jsx}',
|
'packages/(!test)/**/*.{js,jsx}',
|
||||||
'!**/node_modules/**',
|
'!**/node_modules/**',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/build-utils",
|
"name": "@now/build-utils",
|
||||||
"version": "0.5.4",
|
"version": "0.5.5",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.js",
|
"types": "./dist/index.d.js",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { File, Files, Meta } from '../types';
|
|||||||
import { remove, mkdirp, readlink, symlink } from 'fs-extra';
|
import { remove, mkdirp, readlink, symlink } from 'fs-extra';
|
||||||
|
|
||||||
export interface DownloadedFiles {
|
export interface DownloadedFiles {
|
||||||
[filePath: string]: FileFsRef
|
[filePath: string]: FileFsRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
const S_IFMT = 61440; /* 0170000 type of file */
|
const S_IFMT = 61440; /* 0170000 type of file */
|
||||||
@@ -19,7 +19,7 @@ async function downloadFile(file: File, fsPath: string): Promise<FileFsRef> {
|
|||||||
if (mode && isSymbolicLink(mode) && file.type === 'FileFsRef') {
|
if (mode && isSymbolicLink(mode) && file.type === 'FileFsRef') {
|
||||||
const [target] = await Promise.all([
|
const [target] = await Promise.all([
|
||||||
readlink((file as FileFsRef).fsPath),
|
readlink((file as FileFsRef).fsPath),
|
||||||
mkdirp(path.dirname(fsPath))
|
mkdirp(path.dirname(fsPath)),
|
||||||
]);
|
]);
|
||||||
await symlink(target, fsPath);
|
await symlink(target, fsPath);
|
||||||
return FileFsRef.fromFsPath({ mode, fsPath });
|
return FileFsRef.fromFsPath({ mode, fsPath });
|
||||||
@@ -34,12 +34,25 @@ async function removeFile(basePath: string, fileMatched: string) {
|
|||||||
await remove(file);
|
await remove(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function download(files: Files, basePath: string, meta?: Meta): Promise<DownloadedFiles> {
|
export default async function download(
|
||||||
|
files: Files,
|
||||||
|
basePath: string,
|
||||||
|
meta?: Meta
|
||||||
|
): Promise<DownloadedFiles> {
|
||||||
|
const { isDev = false, filesChanged = null, filesRemoved = null } =
|
||||||
|
meta || {};
|
||||||
|
|
||||||
|
if (isDev) {
|
||||||
|
// In `now dev`, the `download()` function is a no-op because
|
||||||
|
// the `basePath` matches the `cwd` of the dev server, so the
|
||||||
|
// source files are already available.
|
||||||
|
return files as DownloadedFiles;
|
||||||
|
}
|
||||||
|
|
||||||
const files2: DownloadedFiles = {};
|
const files2: DownloadedFiles = {};
|
||||||
const { filesChanged = null, filesRemoved = null } = meta || {};
|
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Object.keys(files).map(async (name) => {
|
Object.keys(files).map(async name => {
|
||||||
// If the file does not exist anymore, remove it.
|
// If the file does not exist anymore, remove it.
|
||||||
if (Array.isArray(filesRemoved) && filesRemoved.includes(name)) {
|
if (Array.isArray(filesRemoved) && filesRemoved.includes(name)) {
|
||||||
await removeFile(basePath, name);
|
await removeFile(basePath, name);
|
||||||
@@ -55,7 +68,7 @@ export default async function download(files: Files, basePath: string, meta?: Me
|
|||||||
const fsPath = path.join(basePath, name);
|
const fsPath = path.join(basePath, name);
|
||||||
|
|
||||||
files2[name] = await downloadFile(file, fsPath);
|
files2[name] = await downloadFile(file, fsPath);
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
return files2;
|
return files2;
|
||||||
|
|||||||
@@ -8,12 +8,16 @@ import FileFsRef from '../file-fs-ref';
|
|||||||
type GlobOptions = vanillaGlob_.IOptions;
|
type GlobOptions = vanillaGlob_.IOptions;
|
||||||
|
|
||||||
interface FsFiles {
|
interface FsFiles {
|
||||||
[filePath: string]: FileFsRef
|
[filePath: string]: FileFsRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vanillaGlob = promisify(vanillaGlob_);
|
const vanillaGlob = promisify(vanillaGlob_);
|
||||||
|
|
||||||
export default async function glob(pattern: string, opts: GlobOptions | string, mountpoint?: string): Promise<FsFiles> {
|
export default async function glob(
|
||||||
|
pattern: string,
|
||||||
|
opts: GlobOptions | string,
|
||||||
|
mountpoint?: string
|
||||||
|
): Promise<FsFiles> {
|
||||||
let options: GlobOptions;
|
let options: GlobOptions;
|
||||||
if (typeof opts === 'string') {
|
if (typeof opts === 'string') {
|
||||||
options = { cwd: opts };
|
options = { cwd: opts };
|
||||||
@@ -23,7 +27,7 @@ export default async function glob(pattern: string, opts: GlobOptions | string,
|
|||||||
|
|
||||||
if (!options.cwd) {
|
if (!options.cwd) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Second argument (basePath) must be specified for names of resulting files',
|
'Second argument (basePath) must be specified for names of resulting files'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,11 +45,11 @@ export default async function glob(pattern: string, opts: GlobOptions | string,
|
|||||||
const files = await vanillaGlob(pattern, options);
|
const files = await vanillaGlob(pattern, options);
|
||||||
|
|
||||||
for (const relativePath of files) {
|
for (const relativePath of files) {
|
||||||
const fsPath = path.join(options.cwd!, relativePath);
|
const fsPath = path.join(options.cwd!, relativePath).replace(/\\/g, '/');
|
||||||
let stat: Stats = options.statCache![fsPath] as Stats;
|
let stat: Stats = options.statCache![fsPath] as Stats;
|
||||||
assert(
|
assert(
|
||||||
stat,
|
stat,
|
||||||
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`,
|
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`
|
||||||
);
|
);
|
||||||
if (stat.isFile()) {
|
if (stat.isFile()) {
|
||||||
const isSymlink = options.symlinks![fsPath];
|
const isSymlink = options.symlinks![fsPath];
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ const { shouldServe } = require('@now/build-utils'); // eslint-disable-line impo
|
|||||||
|
|
||||||
exports.analyze = ({ files, entrypoint }) => files[entrypoint].digest;
|
exports.analyze = ({ files, entrypoint }) => files[entrypoint].digest;
|
||||||
|
|
||||||
exports.build = async ({ files, entrypoint }) => {
|
exports.build = async ({
|
||||||
|
workPath, files, entrypoint, meta,
|
||||||
|
}) => {
|
||||||
console.log('downloading files...');
|
console.log('downloading files...');
|
||||||
const srcDir = await getWritableDirectory();
|
|
||||||
const outDir = await getWritableDirectory();
|
const outDir = await getWritableDirectory();
|
||||||
|
|
||||||
await download(files, srcDir);
|
await download(files, workPath, meta);
|
||||||
|
|
||||||
const handlerPath = path.join(__dirname, 'handler');
|
const handlerPath = path.join(__dirname, 'handler');
|
||||||
await copyFile(handlerPath, path.join(outDir, 'handler'));
|
await copyFile(handlerPath, path.join(outDir, 'handler'));
|
||||||
@@ -24,7 +25,7 @@ exports.build = async ({ files, entrypoint }) => {
|
|||||||
|
|
||||||
// For now only the entrypoint file is copied into the lambda
|
// For now only the entrypoint file is copied into the lambda
|
||||||
await copyFile(
|
await copyFile(
|
||||||
path.join(srcDir, entrypoint),
|
path.join(workPath, entrypoint),
|
||||||
path.join(outDir, entrypoint),
|
path.join(outDir, entrypoint),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/cgi",
|
"name": "@now/cgi",
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -125,7 +125,15 @@ export async function downloadGo(
|
|||||||
// If we found GOPATH in ENV, or default `Go` path exists
|
// If we found GOPATH in ENV, or default `Go` path exists
|
||||||
// asssume that user have `Go` installed
|
// asssume that user have `Go` installed
|
||||||
if (isUserGo || process.env.GOPATH !== undefined) {
|
if (isUserGo || process.env.GOPATH !== undefined) {
|
||||||
|
const { stdout } = await execa('go', ['version']);
|
||||||
|
|
||||||
|
if (parseInt(stdout.split('.')[1]) >= 11) {
|
||||||
return createGo(dir, platform, arch);
|
return createGo(dir, platform, arch);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Your current ${stdout} doesn't support Go Modules. Please update.`
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// Check `Go` bin in builder CWD
|
// Check `Go` bin in builder CWD
|
||||||
const isGoExist = await pathExists(join(dir, 'bin'));
|
const isGoExist = await pathExists(join(dir, 'bin'));
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { join, sep, dirname } from 'path';
|
import { join, sep, dirname, basename } from 'path';
|
||||||
import { readFile, writeFile, pathExists, move } from 'fs-extra';
|
import { readFile, writeFile, pathExists, move, copy } from 'fs-extra';
|
||||||
|
import { homedir } from 'os';
|
||||||
|
import execa from 'execa';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
glob,
|
glob,
|
||||||
@@ -14,6 +16,7 @@ import {
|
|||||||
import { createGo, getAnalyzedEntrypoint } from './go-helpers';
|
import { createGo, getAnalyzedEntrypoint } from './go-helpers';
|
||||||
|
|
||||||
interface Analyzed {
|
interface Analyzed {
|
||||||
|
found?: boolean;
|
||||||
packageName: string;
|
packageName: string;
|
||||||
functionName: string;
|
functionName: string;
|
||||||
watch: string[];
|
watch: string[];
|
||||||
@@ -28,6 +31,18 @@ interface BuildParamsType extends BuildOptions {
|
|||||||
meta: BuildParamsMeta;
|
meta: BuildParamsMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize private git repo for Go Modules
|
||||||
|
async function initPrivateGit(credentials: string) {
|
||||||
|
await execa('git', [
|
||||||
|
'config',
|
||||||
|
'--global',
|
||||||
|
'credential.helper',
|
||||||
|
`store --file ${join(homedir(), '.git-credentials')}`,
|
||||||
|
]);
|
||||||
|
|
||||||
|
await writeFile(join(homedir(), '.git-credentials'), credentials);
|
||||||
|
}
|
||||||
|
|
||||||
export const version = 2;
|
export const version = 2;
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
@@ -38,8 +53,14 @@ export async function build({
|
|||||||
files,
|
files,
|
||||||
entrypoint,
|
entrypoint,
|
||||||
config,
|
config,
|
||||||
|
workPath,
|
||||||
meta = {} as BuildParamsMeta,
|
meta = {} as BuildParamsMeta,
|
||||||
}: BuildParamsType) {
|
}: BuildParamsType) {
|
||||||
|
if (process.env.GIT_CREDENTIALS && !meta.isDev) {
|
||||||
|
console.log('Initialize Git credentials...');
|
||||||
|
await initPrivateGit(process.env.GIT_CREDENTIALS);
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Downloading user files...');
|
console.log('Downloading user files...');
|
||||||
const entrypointArr = entrypoint.split(sep);
|
const entrypointArr = entrypoint.split(sep);
|
||||||
|
|
||||||
@@ -48,26 +69,12 @@ export async function build({
|
|||||||
getWriteableDirectory(),
|
getWriteableDirectory(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (meta.isDev) {
|
|
||||||
const devGoPath = `dev${entrypointArr[entrypointArr.length - 1]}`;
|
|
||||||
const goPathArr = goPath.split(sep);
|
|
||||||
goPathArr.pop();
|
|
||||||
goPathArr.push(devGoPath);
|
|
||||||
goPath = goPathArr.join(sep);
|
|
||||||
}
|
|
||||||
|
|
||||||
const srcPath = join(goPath, 'src', 'lambda');
|
const srcPath = join(goPath, 'src', 'lambda');
|
||||||
const downloadedFiles = await download(files, srcPath);
|
let downloadedFiles;
|
||||||
const input = dirname(downloadedFiles[entrypoint].fsPath);
|
if (meta.isDev) {
|
||||||
var includedFiles: Files = {};
|
downloadedFiles = await download(files, workPath, meta);
|
||||||
|
} else {
|
||||||
if (config && config.includeFiles) {
|
downloadedFiles = await download(files, srcPath);
|
||||||
for (const pattern of config.includeFiles) {
|
|
||||||
const files = await glob(pattern, input);
|
|
||||||
for (const assetName of Object.keys(files)) {
|
|
||||||
includedFiles[assetName] = files[assetName];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Parsing AST for "${entrypoint}"`);
|
console.log(`Parsing AST for "${entrypoint}"`);
|
||||||
@@ -81,24 +88,79 @@ export async function build({
|
|||||||
|
|
||||||
if (!analyzed) {
|
if (!analyzed) {
|
||||||
const err = new Error(
|
const err = new Error(
|
||||||
`Could not find an exported function in "${entrypoint}"`
|
`Could not find an exported function in "${entrypoint}"
|
||||||
|
Learn more: https://zeit.co/docs/v2/deployments/official-builders/go-now-go/#entrypoint
|
||||||
|
`
|
||||||
);
|
);
|
||||||
console.log(err.message);
|
console.log(err.message);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const entrypointDirnameDev = dirname(downloadedFiles[entrypoint].fsPath);
|
||||||
const parsedAnalyzed = JSON.parse(analyzed) as Analyzed;
|
const parsedAnalyzed = JSON.parse(analyzed) as Analyzed;
|
||||||
|
|
||||||
|
if (meta.isDev) {
|
||||||
|
const base = dirname(downloadedFiles['now.json'].fsPath);
|
||||||
|
const destNow = join(
|
||||||
|
base,
|
||||||
|
'.now',
|
||||||
|
'cache',
|
||||||
|
basename(entrypoint, '.go'),
|
||||||
|
'src',
|
||||||
|
'lambda'
|
||||||
|
);
|
||||||
|
const goMod = await pathExists(join(entrypointDirnameDev, 'go.mod'));
|
||||||
|
|
||||||
|
// this will ensure Go rebuilt fast
|
||||||
|
goPath = join(base, '.now', 'cache', basename(entrypoint, '.go'));
|
||||||
|
|
||||||
|
for (const file of parsedAnalyzed.watch) {
|
||||||
|
if (entrypointArr.length > 0) {
|
||||||
|
await copy(
|
||||||
|
join(base, dirname(entrypoint), file),
|
||||||
|
join(destNow, dirname(entrypoint), file)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (goMod) {
|
||||||
|
await copy(
|
||||||
|
join(entrypointDirnameDev, 'go.mod'),
|
||||||
|
join(destNow, dirname(entrypoint), 'go.mod')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await copy(join(base, file), join(destNow, file));
|
||||||
|
|
||||||
|
if (goMod) {
|
||||||
|
await copy(
|
||||||
|
join(entrypointDirnameDev, 'go.mod'),
|
||||||
|
join(destNow, 'go.mod')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
downloadedFiles = await glob('**', destNow);
|
||||||
|
}
|
||||||
|
|
||||||
|
const entrypointDirname = dirname(downloadedFiles[entrypoint].fsPath);
|
||||||
|
const input = entrypointDirname;
|
||||||
|
var includedFiles: Files = {};
|
||||||
|
|
||||||
|
if (config && config.includeFiles) {
|
||||||
|
for (const pattern of config.includeFiles) {
|
||||||
|
const files = await glob(pattern, input);
|
||||||
|
for (const assetName of Object.keys(files)) {
|
||||||
|
includedFiles[assetName] = files[assetName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handlerFunctionName = parsedAnalyzed.functionName;
|
const handlerFunctionName = parsedAnalyzed.functionName;
|
||||||
console.log(
|
console.log(
|
||||||
`Found exported function "${handlerFunctionName}" in "${entrypoint}"`
|
`Found exported function "${handlerFunctionName}" in "${entrypoint}"`
|
||||||
);
|
);
|
||||||
|
|
||||||
// we need `main.go` in the same dir as the entrypoint,
|
|
||||||
// otherwise `go build` will refuse to build
|
|
||||||
const entrypointDirname = dirname(downloadedFiles[entrypoint].fsPath);
|
|
||||||
|
|
||||||
// check if package name other than main
|
// check if package name other than main
|
||||||
|
// using `go.mod` way building the handler
|
||||||
const packageName = parsedAnalyzed.packageName;
|
const packageName = parsedAnalyzed.packageName;
|
||||||
const isGoModExist = await pathExists(join(entrypointDirname, 'go.mod'));
|
const isGoModExist = await pathExists(join(entrypointDirname, 'go.mod'));
|
||||||
if (packageName !== 'main') {
|
if (packageName !== 'main') {
|
||||||
@@ -225,6 +287,9 @@ export async function build({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// legacy mode
|
||||||
|
// we need `main.go` in the same dir as the entrypoint,
|
||||||
|
// otherwise `go build` will refuse to build
|
||||||
const go = await createGo(
|
const go = await createGo(
|
||||||
goPath,
|
goPath,
|
||||||
process.platform,
|
process.platform,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/go",
|
"name": "@now/go",
|
||||||
"version": "0.4.5",
|
"version": "0.5.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
22
packages/now-go/test/fixtures/09-exported-function/index.go
vendored
Normal file
22
packages/now-go/test/fixtures/09-exported-function/index.go
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package function
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Person struct
|
||||||
|
type Person struct {
|
||||||
|
name string
|
||||||
|
age int
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPerson struct method
|
||||||
|
func NewPerson(name string, age int) *Person {
|
||||||
|
return &Person{name: name, age: age}
|
||||||
|
}
|
||||||
|
|
||||||
|
// H func
|
||||||
|
func H(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprintf(w, "RANDOMNESS_PLACEHOLDER")
|
||||||
|
}
|
||||||
9
packages/now-go/test/fixtures/09-exported-function/now.json
vendored
Normal file
9
packages/now-go/test/fixtures/09-exported-function/now.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [
|
||||||
|
{ "src": "index.go", "use": "@now/go" }
|
||||||
|
],
|
||||||
|
"probes": [
|
||||||
|
{ "path": "/", "mustContain": "RANDOMNESS_PLACEHOLDER" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -10,9 +10,22 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ignoredFoldersRegex []*regexp.Regexp
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ignoredFolders := []string{"vendor", "testdata", ".now"}
|
||||||
|
|
||||||
|
// Build the regex that matches if a path contains the respective ignored folder
|
||||||
|
// The pattern will look like: (.*/)?vendor/.*, which matches every path that contains a vendor folder
|
||||||
|
for _, folder := range ignoredFolders {
|
||||||
|
ignoredFoldersRegex = append(ignoredFoldersRegex, regexp.MustCompile("(.*/)?"+folder+"/.*"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type analyze struct {
|
type analyze struct {
|
||||||
PackageName string `json:"packageName"`
|
PackageName string `json:"packageName"`
|
||||||
FuncName string `json:"functionName"`
|
FuncName string `json:"functionName"`
|
||||||
@@ -40,8 +53,9 @@ func visit(files *[]string) filepath.WalkFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we don't need Dirs, or test files
|
// we don't need Dirs, or test files
|
||||||
// we only want `.go` files
|
// we only want `.go` files. Further, we ignore
|
||||||
if info.IsDir() || itf || filepath.Ext(path) != ".go" {
|
// every file that is in one of the ignored folders.
|
||||||
|
if info.IsDir() || itf || filepath.Ext(path) != ".go" || isInIgnoredFolder(path) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +64,19 @@ func visit(files *[]string) filepath.WalkFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isInIgnoredFolder checks if the given path is in one of the ignored folders.
|
||||||
|
func isInIgnoredFolder(path string) bool {
|
||||||
|
// Make sure the regex works for Windows paths
|
||||||
|
path = filepath.ToSlash(path)
|
||||||
|
|
||||||
|
for _, pattern := range ignoredFoldersRegex {
|
||||||
|
if pattern.MatchString(path) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// return unique file
|
// return unique file
|
||||||
func unique(files []string) []string {
|
func unique(files []string) []string {
|
||||||
encountered := map[string]bool{}
|
encountered := map[string]bool{}
|
||||||
@@ -138,24 +165,32 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parsed := parse(fileName)
|
parsed := parse(fileName)
|
||||||
|
offset := parsed.Pos()
|
||||||
|
reqRep := "*http.Request http.ResponseWriter"
|
||||||
|
|
||||||
for _, decl := range parsed.Decls {
|
for _, decl := range parsed.Decls {
|
||||||
fn, ok := decl.(*ast.FuncDecl)
|
fn, ok := decl.(*ast.FuncDecl)
|
||||||
if !ok {
|
if !ok {
|
||||||
// this declaraction is not a function
|
// this declaration is not a function
|
||||||
// so we're not interested
|
// so we're not interested
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if fn.Name.IsExported() == true {
|
if fn.Name.IsExported() == true {
|
||||||
// we found the first exported function
|
// find a valid `net/http` handler function
|
||||||
|
for _, param := range fn.Type.Params.List {
|
||||||
|
if strings.Contains(reqRep, string(rf[param.Type.Pos()-offset:param.Type.End()-offset])) {
|
||||||
|
// we found the first exported function with `net/http`
|
||||||
// we're done!
|
// we're done!
|
||||||
analyzed := analyze{
|
analyzed := analyze{
|
||||||
PackageName: parsed.Name.Name,
|
PackageName: parsed.Name.Name,
|
||||||
FuncName: fn.Name.Name,
|
FuncName: fn.Name.Name,
|
||||||
Watch: unique(relatedFiles),
|
Watch: unique(relatedFiles),
|
||||||
}
|
}
|
||||||
json, _ := json.Marshal(analyzed)
|
analyzedJSON, _ := json.Marshal(analyzed)
|
||||||
fmt.Print(string(json))
|
fmt.Print(string(analyzedJSON))
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ const { runNpmInstall } = require('@now/build-utils/fs/run-user-scripts.js'); //
|
|||||||
|
|
||||||
const writeFile = promisify(fs.writeFile);
|
const writeFile = promisify(fs.writeFile);
|
||||||
|
|
||||||
exports.build = async ({ files, entrypoint, workPath }) => {
|
exports.build = async ({
|
||||||
|
files, entrypoint, workPath, meta,
|
||||||
|
}) => {
|
||||||
console.log('downloading user files...');
|
console.log('downloading user files...');
|
||||||
const downloadedFiles = await download(files, workPath);
|
const downloadedFiles = await download(files, workPath, meta);
|
||||||
console.log('writing package.json...');
|
console.log('writing package.json...');
|
||||||
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');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/mdx-deck",
|
"name": "@now/mdx-deck",
|
||||||
"version": "0.5.3",
|
"version": "0.5.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/next",
|
"name": "@now/next",
|
||||||
"version": "0.3.1",
|
"version": "0.4.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"directory": "packages/now-next"
|
"directory": "packages/now-next"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@now/node-bridge": "^1.1.2",
|
"@now/node-bridge": "^1.1.3",
|
||||||
"fs-extra": "^7.0.0",
|
"fs-extra": "^7.0.0",
|
||||||
"get-port": "^5.0.0",
|
"get-port": "^5.0.0",
|
||||||
"resolve-from": "^5.0.0",
|
"resolve-from": "^5.0.0",
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import {
|
|||||||
getRoutes,
|
getRoutes,
|
||||||
includeOnlyEntryDirectory,
|
includeOnlyEntryDirectory,
|
||||||
normalizePackageJson,
|
normalizePackageJson,
|
||||||
onlyStaticDirectory,
|
filesFromDirectory,
|
||||||
stringMap,
|
stringMap,
|
||||||
syncEnvVars,
|
syncEnvVars,
|
||||||
validateEntrypoint,
|
validateEntrypoint,
|
||||||
@@ -155,14 +155,13 @@ export const build = async ({
|
|||||||
entrypoint,
|
entrypoint,
|
||||||
meta = {} as BuildParamsMeta,
|
meta = {} as BuildParamsMeta,
|
||||||
}: BuildParamsType): Promise<{
|
}: BuildParamsType): Promise<{
|
||||||
routes?: any[];
|
routes?: { src: string; dest: string }[];
|
||||||
output: Files;
|
output: Files;
|
||||||
watch?: string[];
|
watch?: string[];
|
||||||
childProcesses: ChildProcess[];
|
childProcesses: ChildProcess[];
|
||||||
}> => {
|
}> => {
|
||||||
validateEntrypoint(entrypoint);
|
validateEntrypoint(entrypoint);
|
||||||
|
|
||||||
const routes: any[] = [];
|
|
||||||
const entryDirectory = path.dirname(entrypoint);
|
const entryDirectory = path.dirname(entrypoint);
|
||||||
const entryPath = path.join(workPath, entryDirectory);
|
const entryPath = path.join(workPath, entryDirectory);
|
||||||
const dotNext = path.join(entryPath, '.next');
|
const dotNext = path.join(entryPath, '.next');
|
||||||
@@ -191,6 +190,10 @@ export const build = async ({
|
|||||||
console.log(`${name} Installing dependencies...`);
|
console.log(`${name} Installing dependencies...`);
|
||||||
await runNpmInstall(entryPath, ['--prefer-offline']);
|
await runNpmInstall(entryPath, ['--prefer-offline']);
|
||||||
|
|
||||||
|
if (!process.env.NODE_ENV) {
|
||||||
|
process.env.NODE_ENV = 'development';
|
||||||
|
}
|
||||||
|
|
||||||
// The runtime env vars consist of the base `process.env` vars, but with the
|
// The runtime env vars consist of the base `process.env` vars, but with the
|
||||||
// build env vars removed, and the runtime env vars mixed in afterwards
|
// build env vars removed, and the runtime env vars mixed in afterwards
|
||||||
const runtimeEnv: EnvConfig = Object.assign({}, process.env);
|
const runtimeEnv: EnvConfig = Object.assign({}, process.env);
|
||||||
@@ -285,7 +288,9 @@ export const build = async ({
|
|||||||
await unlinkFile(path.join(entryPath, '.npmrc'));
|
await unlinkFile(path.join(entryPath, '.npmrc'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const routes: { src: string; dest: string }[] = [];
|
||||||
const lambdas: { [key: string]: Lambda } = {};
|
const lambdas: { [key: string]: Lambda } = {};
|
||||||
|
const staticPages: { [key: string]: FileFsRef } = {};
|
||||||
|
|
||||||
if (isLegacy) {
|
if (isLegacy) {
|
||||||
const filesAfterBuild = await glob('**', entryPath);
|
const filesAfterBuild = await glob('**', entryPath);
|
||||||
@@ -377,10 +382,21 @@ export const build = async ({
|
|||||||
fsPath: path.join(__dirname, 'launcher.js'),
|
fsPath: path.join(__dirname, 'launcher.js'),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
const pages = await glob(
|
const pagesDir = path.join(entryPath, '.next', 'serverless', 'pages');
|
||||||
'**/*.js',
|
|
||||||
path.join(entryPath, '.next', 'serverless', 'pages')
|
const pages = await glob('**/*.js', pagesDir);
|
||||||
);
|
const staticPageFiles = await glob('**/*.html', pagesDir);
|
||||||
|
|
||||||
|
Object.keys(staticPageFiles).forEach((page: string) => {
|
||||||
|
const staticRoute = path.join(entryDirectory, page);
|
||||||
|
staticPages[staticRoute] = staticPageFiles[page];
|
||||||
|
|
||||||
|
const pathname = page.replace(/\.html$/, '');
|
||||||
|
routes.push({
|
||||||
|
src: `^${path.join('/', entryDirectory, pathname)}$`,
|
||||||
|
dest: path.join('/', staticRoute),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const pageKeys = Object.keys(pages);
|
const pageKeys = Object.keys(pages);
|
||||||
|
|
||||||
@@ -448,14 +464,32 @@ export const build = async ({
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
const staticDirectoryFiles = onlyStaticDirectory(
|
const entryDirectoryFiles = includeOnlyEntryDirectory(files, entryDirectory);
|
||||||
includeOnlyEntryDirectory(files, entryDirectory),
|
const staticDirectoryFiles = filesFromDirectory(
|
||||||
entryDirectory
|
entryDirectoryFiles,
|
||||||
|
path.join(entryDirectory, 'static')
|
||||||
|
);
|
||||||
|
const publicDirectoryFiles = filesFromDirectory(
|
||||||
|
entryDirectoryFiles,
|
||||||
|
path.join(entryDirectory, 'public')
|
||||||
|
);
|
||||||
|
const publicFiles = Object.keys(publicDirectoryFiles).reduce(
|
||||||
|
(mappedFiles, file) => ({
|
||||||
|
...mappedFiles,
|
||||||
|
[file.replace(/public[/\\]+/, '')]: publicDirectoryFiles[file],
|
||||||
|
}),
|
||||||
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
output: { ...lambdas, ...staticFiles, ...staticDirectoryFiles },
|
output: {
|
||||||
routes: [],
|
...publicFiles,
|
||||||
|
...lambdas,
|
||||||
|
...staticPages,
|
||||||
|
...staticFiles,
|
||||||
|
...staticDirectoryFiles,
|
||||||
|
},
|
||||||
|
routes,
|
||||||
watch: [],
|
watch: [],
|
||||||
childProcesses: [],
|
childProcesses: [],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
if (!process.env.NODE_ENV) {
|
if (!process.env.NODE_ENV) {
|
||||||
process.env.NODE_ENV = process.env.NOW_REGION === 'dev1' ? 'development' : 'production';
|
process.env.NODE_ENV =
|
||||||
|
process.env.NOW_REGION === 'dev1' ? 'development' : 'production';
|
||||||
}
|
}
|
||||||
|
|
||||||
const { Server } = require('http');
|
const { Server } = require('http');
|
||||||
const { Bridge } = require('./now__bridge');
|
const { Bridge } = require('./now__bridge');
|
||||||
const page = require('./page');
|
const page = require('./page');
|
||||||
|
|
||||||
const server = new Server(page.render);
|
// page.render is for React rendering
|
||||||
|
// page.default is for /api rendering
|
||||||
|
// page is for module.exports in /api
|
||||||
|
const server = new Server(page.render || page.default || page);
|
||||||
const bridge = new Bridge(server);
|
const bridge = new Bridge(server);
|
||||||
bridge.listen();
|
bridge.listen();
|
||||||
|
|
||||||
|
|||||||
@@ -73,11 +73,11 @@ function excludeLockFiles(files: Files): Files {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include the static directory from files
|
* Include only the files from a selected directory
|
||||||
*/
|
*/
|
||||||
function onlyStaticDirectory(files: Files, entryDir: string): Files {
|
function filesFromDirectory(files: Files, dir: string): Files {
|
||||||
function matcher(filePath: string) {
|
function matcher(filePath: string) {
|
||||||
return !filePath.startsWith(path.join(entryDir, 'static'));
|
return !filePath.startsWith(dir.replace(/\\/g, '/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return excludeFiles(files, matcher);
|
return excludeFiles(files, matcher);
|
||||||
@@ -195,8 +195,9 @@ function getRoutes(
|
|||||||
dest: `${url}/static/$1`,
|
dest: `${url}/static/$1`,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
const filePaths = Object.keys(filesInside);
|
||||||
|
|
||||||
for (const file of Object.keys(filesInside)) {
|
for (const file of filePaths) {
|
||||||
const relativePath = path.relative(entryDirectory, file);
|
const relativePath = path.relative(entryDirectory, file);
|
||||||
const isPage = pathIsInside('pages', relativePath);
|
const isPage = pathIsInside('pages', relativePath);
|
||||||
|
|
||||||
@@ -227,6 +228,25 @@ function getRoutes(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add public folder routes
|
||||||
|
for (const file of filePaths) {
|
||||||
|
const relativePath = path.relative(entryDirectory, file);
|
||||||
|
const isPublic = pathIsInside('public', relativePath);
|
||||||
|
|
||||||
|
if (!isPublic) continue;
|
||||||
|
|
||||||
|
const fileName = path.relative('public', relativePath);
|
||||||
|
const route = {
|
||||||
|
src: `${prefix}${fileName}`,
|
||||||
|
dest: `${url}/${fileName}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Only add the route if a page is not already using it
|
||||||
|
if (!routes.some(r => r.src === route.src)) {
|
||||||
|
routes.push(route);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return routes;
|
return routes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +270,7 @@ export {
|
|||||||
includeOnlyEntryDirectory,
|
includeOnlyEntryDirectory,
|
||||||
excludeLockFiles,
|
excludeLockFiles,
|
||||||
normalizePackageJson,
|
normalizePackageJson,
|
||||||
onlyStaticDirectory,
|
filesFromDirectory,
|
||||||
getNextConfig,
|
getNextConfig,
|
||||||
getPathsInside,
|
getPathsInside,
|
||||||
getRoutes,
|
getRoutes,
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ it(
|
|||||||
} = await runBuildLambda(path.join(__dirname, 'monorepo'));
|
} = await runBuildLambda(path.join(__dirname, 'monorepo'));
|
||||||
expect(output['www/index']).toBeDefined();
|
expect(output['www/index']).toBeDefined();
|
||||||
expect(output['www/static/test.txt']).toBeDefined();
|
expect(output['www/static/test.txt']).toBeDefined();
|
||||||
|
expect(output['www/data.txt']).toBeDefined();
|
||||||
const filePaths = Object.keys(output);
|
const filePaths = Object.keys(output);
|
||||||
const hasUnderScoreAppStaticFile = filePaths.some(filePath => filePath.match(/static.*\/pages\/_app\.js$/));
|
const hasUnderScoreAppStaticFile = filePaths.some(filePath => filePath.match(/static.*\/pages\/_app\.js$/));
|
||||||
const hasUnderScoreErrorStaticFile = filePaths.some(filePath => filePath.match(/static.*\/pages\/_error\.js$/));
|
const hasUnderScoreErrorStaticFile = filePaths.some(filePath => filePath.match(/static.*\/pages\/_error\.js$/));
|
||||||
@@ -96,3 +97,14 @@ it(
|
|||||||
},
|
},
|
||||||
FOUR_MINUTES,
|
FOUR_MINUTES,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it(
|
||||||
|
'Should build the public-files test',
|
||||||
|
async () => {
|
||||||
|
const {
|
||||||
|
buildResult: { output },
|
||||||
|
} = await runBuildLambda(path.join(__dirname, 'public-files'));
|
||||||
|
expect(output['robots.txt']).toBeDefined();
|
||||||
|
},
|
||||||
|
FOUR_MINUTES,
|
||||||
|
);
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
data
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
target: 'serverless',
|
||||||
|
};
|
||||||
6
packages/now-next/test/integration/public-files/now.json
Normal file
6
packages/now-next/test/integration/public-files/now.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [
|
||||||
|
{"src": "next.config.js", "use": "@now/next"}
|
||||||
|
]
|
||||||
|
}
|
||||||
10
packages/now-next/test/integration/public-files/package.json
Normal file
10
packages/now-next/test/integration/public-files/package.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"now-build": "next build"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"next": "8",
|
||||||
|
"react": "16",
|
||||||
|
"react-dom": "16"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export default () => 'Index page';
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
User-agent: *
|
||||||
|
Disallow: /
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const { build } = require('@now/next');
|
const { build } = require('@now/next');
|
||||||
const { FileBlob } = require('@now/build-utils');
|
const { download, FileBlob } = require('@now/build-utils');
|
||||||
|
|
||||||
jest.setTimeout(45000);
|
jest.setTimeout(45000);
|
||||||
|
|
||||||
@@ -22,6 +22,15 @@ describe('build meta dev', () => {
|
|||||||
export default () => 'Index page'
|
export default () => 'Index page'
|
||||||
`,
|
`,
|
||||||
}),
|
}),
|
||||||
|
// This file should be omitted because `pages/index.js` will use the same route
|
||||||
|
'public/index': new FileBlob({
|
||||||
|
mode: 0o777,
|
||||||
|
data: 'text',
|
||||||
|
}),
|
||||||
|
'public/data.txt': new FileBlob({
|
||||||
|
mode: 0o777,
|
||||||
|
data: 'data',
|
||||||
|
}),
|
||||||
'package.json': new FileBlob({
|
'package.json': new FileBlob({
|
||||||
mode: 0o777,
|
mode: 0o777,
|
||||||
data: `
|
data: `
|
||||||
@@ -46,24 +55,12 @@ describe('build meta dev', () => {
|
|||||||
.slice(3),
|
.slice(3),
|
||||||
);
|
);
|
||||||
console.log('workPath directory: ', workPath);
|
console.log('workPath directory: ', workPath);
|
||||||
/*
|
|
||||||
it('should have builder v2 response isDev=false', async () => {
|
|
||||||
const meta = { isDev: false, requestPath: null };
|
|
||||||
const { output, routes, watch } = await build({
|
|
||||||
files,
|
|
||||||
workPath,
|
|
||||||
entrypoint,
|
|
||||||
meta,
|
|
||||||
});
|
|
||||||
//console.log('output: ', Object.keys(output));
|
|
||||||
expect(Object.keys(output).length).toBe(7);
|
|
||||||
expect(output.index.type).toBe('Lambda');
|
|
||||||
expect(routes.length).toBe(0);
|
|
||||||
expect(watch.length).toBe(0);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
it('should have builder v2 response isDev=true', async () => {
|
it('should have builder v2 response isDev=true', async () => {
|
||||||
|
// Since `download()` is a no-op when `isDev=true`, the assumption is that the
|
||||||
|
// source files are already present, so manually download them here first.
|
||||||
|
await download(files, workPath);
|
||||||
|
|
||||||
const meta = { isDev: true, requestPath: null };
|
const meta = { isDev: true, requestPath: null };
|
||||||
const {
|
const {
|
||||||
output, routes, watch, childProcesses,
|
output, routes, watch, childProcesses,
|
||||||
@@ -83,8 +80,15 @@ describe('build meta dev', () => {
|
|||||||
{ src: '/static/(.*)', dest: 'http://localhost:5000/static/$1' },
|
{ src: '/static/(.*)', dest: 'http://localhost:5000/static/$1' },
|
||||||
{ src: '/index', dest: 'http://localhost:5000/index' },
|
{ src: '/index', dest: 'http://localhost:5000/index' },
|
||||||
{ src: '/', dest: 'http://localhost:5000/' },
|
{ src: '/', dest: 'http://localhost:5000/' },
|
||||||
|
{ src: '/data.txt', dest: 'http://localhost:5000/data.txt' },
|
||||||
|
]);
|
||||||
|
expect(watch).toEqual([
|
||||||
|
'next.config.js',
|
||||||
|
'pages/index.js',
|
||||||
|
'public/index',
|
||||||
|
'public/data.txt',
|
||||||
|
'package.json',
|
||||||
]);
|
]);
|
||||||
expect(watch).toEqual(['next.config.js', 'pages/index.js', 'package.json']);
|
|
||||||
childProcesses.forEach(cp => cp.kill());
|
childProcesses.forEach(cp => cp.kill());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/node-bridge",
|
"name": "@now/node-bridge",
|
||||||
"version": "1.1.2",
|
"version": "1.1.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { AddressInfo } from 'net';
|
import { AddressInfo } from 'net';
|
||||||
import { APIGatewayProxyEvent } from 'aws-lambda';
|
import { APIGatewayProxyEvent, Context } from 'aws-lambda';
|
||||||
import {
|
import {
|
||||||
Server,
|
Server,
|
||||||
IncomingHttpHeaders,
|
IncomingHttpHeaders,
|
||||||
OutgoingHttpHeaders,
|
OutgoingHttpHeaders,
|
||||||
request
|
request,
|
||||||
} from 'http';
|
} from 'http';
|
||||||
|
|
||||||
interface NowProxyEvent {
|
interface NowProxyEvent {
|
||||||
@@ -133,25 +133,25 @@ export class Bridge {
|
|||||||
|
|
||||||
return this.server.listen({
|
return this.server.listen({
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
port: 0
|
port: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async launcher(
|
async launcher(
|
||||||
event: NowProxyEvent | APIGatewayProxyEvent
|
event: NowProxyEvent | APIGatewayProxyEvent,
|
||||||
|
context: Context
|
||||||
): Promise<NowProxyResponse> {
|
): Promise<NowProxyResponse> {
|
||||||
|
context.callbackWaitsForEmptyEventLoop = false;
|
||||||
const { port } = await this.listening;
|
const { port } = await this.listening;
|
||||||
|
|
||||||
const { isApiGateway, method, path, headers, body } = normalizeEvent(
|
const { isApiGateway, method, path, headers, body } = normalizeEvent(event);
|
||||||
event
|
|
||||||
);
|
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
hostname: '127.0.0.1',
|
hostname: '127.0.0.1',
|
||||||
port,
|
port,
|
||||||
path,
|
path,
|
||||||
method,
|
method,
|
||||||
headers
|
headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line consistent-return
|
// eslint-disable-next-line consistent-return
|
||||||
@@ -175,7 +175,7 @@ export class Bridge {
|
|||||||
statusCode: response.statusCode || 200,
|
statusCode: response.statusCode || 200,
|
||||||
headers: response.headers,
|
headers: response.headers,
|
||||||
body: bodyBuffer.toString('base64'),
|
body: bodyBuffer.toString('base64'),
|
||||||
encoding: 'base64'
|
encoding: 'base64',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,42 +16,53 @@ test('port binding', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('`APIGatewayProxyEvent` normalizing', async () => {
|
test('`APIGatewayProxyEvent` normalizing', async () => {
|
||||||
const server = new Server((req, res) => res.end(
|
const server = new Server((req, res) =>
|
||||||
|
res.end(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
method: req.method,
|
method: req.method,
|
||||||
path: req.url,
|
path: req.url,
|
||||||
headers: req.headers,
|
headers: req.headers,
|
||||||
}),
|
})
|
||||||
));
|
)
|
||||||
|
);
|
||||||
const bridge = new Bridge(server);
|
const bridge = new Bridge(server);
|
||||||
bridge.listen();
|
bridge.listen();
|
||||||
const result = await bridge.launcher({
|
const context = {};
|
||||||
|
const result = await bridge.launcher(
|
||||||
|
{
|
||||||
httpMethod: 'GET',
|
httpMethod: 'GET',
|
||||||
headers: { foo: 'bar' },
|
headers: { foo: 'bar' },
|
||||||
path: '/apigateway',
|
path: '/apigateway',
|
||||||
body: null,
|
body: null,
|
||||||
});
|
},
|
||||||
|
context
|
||||||
|
);
|
||||||
assert.equal(result.encoding, 'base64');
|
assert.equal(result.encoding, 'base64');
|
||||||
assert.equal(result.statusCode, 200);
|
assert.equal(result.statusCode, 200);
|
||||||
const body = JSON.parse(Buffer.from(result.body, 'base64').toString());
|
const body = JSON.parse(Buffer.from(result.body, 'base64').toString());
|
||||||
assert.equal(body.method, 'GET');
|
assert.equal(body.method, 'GET');
|
||||||
assert.equal(body.path, '/apigateway');
|
assert.equal(body.path, '/apigateway');
|
||||||
assert.equal(body.headers.foo, 'bar');
|
assert.equal(body.headers.foo, 'bar');
|
||||||
|
assert.equal(context.callbackWaitsForEmptyEventLoop, false);
|
||||||
|
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`NowProxyEvent` normalizing', async () => {
|
test('`NowProxyEvent` normalizing', async () => {
|
||||||
const server = new Server((req, res) => res.end(
|
const server = new Server((req, res) =>
|
||||||
|
res.end(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
method: req.method,
|
method: req.method,
|
||||||
path: req.url,
|
path: req.url,
|
||||||
headers: req.headers,
|
headers: req.headers,
|
||||||
}),
|
})
|
||||||
));
|
)
|
||||||
|
);
|
||||||
const bridge = new Bridge(server);
|
const bridge = new Bridge(server);
|
||||||
bridge.listen();
|
bridge.listen();
|
||||||
const result = await bridge.launcher({
|
const context = { callbackWaitsForEmptyEventLoop: true };
|
||||||
|
const result = await bridge.launcher(
|
||||||
|
{
|
||||||
Action: 'Invoke',
|
Action: 'Invoke',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -59,13 +70,16 @@ test('`NowProxyEvent` normalizing', async () => {
|
|||||||
path: '/nowproxy',
|
path: '/nowproxy',
|
||||||
body: 'body=1',
|
body: 'body=1',
|
||||||
}),
|
}),
|
||||||
});
|
},
|
||||||
|
context
|
||||||
|
);
|
||||||
assert.equal(result.encoding, 'base64');
|
assert.equal(result.encoding, 'base64');
|
||||||
assert.equal(result.statusCode, 200);
|
assert.equal(result.statusCode, 200);
|
||||||
const body = JSON.parse(Buffer.from(result.body, 'base64').toString());
|
const body = JSON.parse(Buffer.from(result.body, 'base64').toString());
|
||||||
assert.equal(body.method, 'POST');
|
assert.equal(body.method, 'POST');
|
||||||
assert.equal(body.path, '/nowproxy');
|
assert.equal(body.path, '/nowproxy');
|
||||||
assert.equal(body.headers.foo, 'baz');
|
assert.equal(body.headers.foo, 'baz');
|
||||||
|
assert.equal(context.callbackWaitsForEmptyEventLoop, false);
|
||||||
|
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,11 +28,13 @@ const { shouldServe } = require('@now/build-utils'); // eslint-disable-line impo
|
|||||||
* @param {string[]} [options.npmArguments]
|
* @param {string[]} [options.npmArguments]
|
||||||
*/
|
*/
|
||||||
async function downloadInstallAndBundle(
|
async function downloadInstallAndBundle(
|
||||||
{ files, entrypoint, workPath },
|
{
|
||||||
|
files, entrypoint, workPath, meta,
|
||||||
|
},
|
||||||
{ npmArguments = [] } = {},
|
{ npmArguments = [] } = {},
|
||||||
) {
|
) {
|
||||||
console.log('downloading user files...');
|
console.log('downloading user files...');
|
||||||
const downloadedFiles = await download(files, workPath);
|
const downloadedFiles = await download(files, workPath, meta);
|
||||||
|
|
||||||
console.log("installing dependencies for user's code...");
|
console.log("installing dependencies for user's code...");
|
||||||
const entrypointFsDirname = path.join(workPath, path.dirname(entrypoint));
|
const entrypointFsDirname = path.join(workPath, path.dirname(entrypoint));
|
||||||
@@ -99,10 +101,12 @@ exports.config = {
|
|||||||
* @returns {Promise<Files>}
|
* @returns {Promise<Files>}
|
||||||
*/
|
*/
|
||||||
exports.build = async ({
|
exports.build = async ({
|
||||||
files, entrypoint, config, workPath,
|
files, entrypoint, config, workPath, meta,
|
||||||
}) => {
|
}) => {
|
||||||
const [downloadedFiles, entrypointFsDirname] = await downloadInstallAndBundle(
|
const [downloadedFiles, entrypointFsDirname] = await downloadInstallAndBundle(
|
||||||
{ files, entrypoint, workPath },
|
{
|
||||||
|
files, entrypoint, workPath, meta,
|
||||||
|
},
|
||||||
{ npmArguments: ['--prefer-offline'] },
|
{ npmArguments: ['--prefer-offline'] },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/node-server",
|
"name": "@now/node-server",
|
||||||
"version": "0.7.1",
|
"version": "0.7.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -8,8 +8,8 @@
|
|||||||
"directory": "packages/now-node-server"
|
"directory": "packages/now-node-server"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@now/node-bridge": "^1.1.2",
|
"@now/node-bridge": "^1.1.3",
|
||||||
"@zeit/ncc": "0.18.2",
|
"@zeit/ncc": "0.18.5",
|
||||||
"fs-extra": "7.0.1"
|
"fs-extra": "7.0.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/node",
|
"name": "@now/node",
|
||||||
"version": "0.7.1",
|
"version": "0.7.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -9,8 +9,8 @@
|
|||||||
"directory": "packages/now-node"
|
"directory": "packages/now-node"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@now/node-bridge": "^1.1.2",
|
"@now/node-bridge": "^1.1.3",
|
||||||
"@zeit/ncc": "0.18.2",
|
"@zeit/ncc": "0.18.5",
|
||||||
"fs-extra": "7.0.1"
|
"fs-extra": "7.0.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
FileBlob,
|
FileBlob,
|
||||||
FileFsRef,
|
FileFsRef,
|
||||||
Files,
|
Files,
|
||||||
|
Meta,
|
||||||
createLambda,
|
createLambda,
|
||||||
runNpmInstall,
|
runNpmInstall,
|
||||||
runPackageJsonScript,
|
runPackageJsonScript,
|
||||||
@@ -22,6 +23,7 @@ interface DownloadOptions {
|
|||||||
files: Files;
|
files: Files;
|
||||||
entrypoint: string;
|
entrypoint: string;
|
||||||
workPath: string;
|
workPath: string;
|
||||||
|
meta?: Meta;
|
||||||
npmArguments?: string[];
|
npmArguments?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,10 +31,11 @@ async function downloadInstallAndBundle({
|
|||||||
files,
|
files,
|
||||||
entrypoint,
|
entrypoint,
|
||||||
workPath,
|
workPath,
|
||||||
|
meta,
|
||||||
npmArguments = [],
|
npmArguments = [],
|
||||||
}: DownloadOptions) {
|
}: DownloadOptions) {
|
||||||
console.log('downloading user files...');
|
console.log('downloading user files...');
|
||||||
const downloadedFiles = await download(files, workPath);
|
const downloadedFiles = await download(files, workPath, meta);
|
||||||
|
|
||||||
console.log("installing dependencies for user's code...");
|
console.log("installing dependencies for user's code...");
|
||||||
const entrypointFsDirname = join(workPath, dirname(entrypoint));
|
const entrypointFsDirname = join(workPath, dirname(entrypoint));
|
||||||
@@ -110,6 +113,7 @@ export async function build({
|
|||||||
entrypoint,
|
entrypoint,
|
||||||
workPath,
|
workPath,
|
||||||
config,
|
config,
|
||||||
|
meta,
|
||||||
}: BuildOptions) {
|
}: BuildOptions) {
|
||||||
const {
|
const {
|
||||||
entrypointPath,
|
entrypointPath,
|
||||||
@@ -118,6 +122,7 @@ export async function build({
|
|||||||
files,
|
files,
|
||||||
entrypoint,
|
entrypoint,
|
||||||
workPath,
|
workPath,
|
||||||
|
meta,
|
||||||
npmArguments: ['--prefer-offline'],
|
npmArguments: ['--prefer-offline'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,10 @@ exports.config = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.build = async ({
|
exports.build = async ({
|
||||||
files, entrypoint, workPath, config,
|
files, entrypoint, workPath, config, meta,
|
||||||
}) => {
|
}) => {
|
||||||
// Download all files to workPath
|
// Download all files to workPath
|
||||||
const fileDir = path.join(workPath, 'userfiles');
|
const downloadedFiles = await download(files, workPath, meta);
|
||||||
const downloadedFiles = await download(files, fileDir);
|
|
||||||
|
|
||||||
let includedFiles = {};
|
let includedFiles = {};
|
||||||
if (config && config.includeFiles) {
|
if (config && config.includeFiles) {
|
||||||
@@ -25,7 +24,7 @@ exports.build = async ({
|
|||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
for (const pattern of config.includeFiles) {
|
for (const pattern of config.includeFiles) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
const matchedFiles = await glob(pattern, fileDir);
|
const matchedFiles = await glob(pattern, workPath);
|
||||||
Object.assign(includedFiles, matchedFiles);
|
Object.assign(includedFiles, matchedFiles);
|
||||||
}
|
}
|
||||||
// explicit and always include the entrypoint
|
// explicit and always include the entrypoint
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/php",
|
"name": "@now/php",
|
||||||
"version": "0.5.3",
|
"version": "0.5.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { join, dirname } from 'path';
|
import { join, dirname, basename } from 'path';
|
||||||
import execa from 'execa';
|
import execa from 'execa';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
@@ -73,7 +73,16 @@ export const build = async ({
|
|||||||
meta = {},
|
meta = {},
|
||||||
}: BuildOptions) => {
|
}: BuildOptions) => {
|
||||||
console.log('downloading files...');
|
console.log('downloading files...');
|
||||||
const downloadedFiles = await download(originalFiles, workPath);
|
let downloadedFiles = await download(originalFiles, workPath, meta);
|
||||||
|
|
||||||
|
if (meta.isDev) {
|
||||||
|
const base = dirname(downloadedFiles['now.json'].fsPath);
|
||||||
|
const destNow = join(base, '.now', 'cache', basename(entrypoint, '.py'));
|
||||||
|
await download(downloadedFiles, destNow);
|
||||||
|
downloadedFiles = await glob('**', destNow);
|
||||||
|
workPath = destNow;
|
||||||
|
}
|
||||||
|
|
||||||
const foundLockFile = 'Pipfile.lock' in downloadedFiles;
|
const foundLockFile = 'Pipfile.lock' in downloadedFiles;
|
||||||
const pyUserBase = await getWriteableDirectory();
|
const pyUserBase = await getWriteableDirectory();
|
||||||
process.env.PYTHONUSERBASE = pyUserBase;
|
process.env.PYTHONUSERBASE = pyUserBase;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ _now_imported, _now_is_legacy = _now_get_import()
|
|||||||
if _now_is_legacy:
|
if _now_is_legacy:
|
||||||
print('using HTTP Handler')
|
print('using HTTP Handler')
|
||||||
from http.server import HTTPServer
|
from http.server import HTTPServer
|
||||||
|
from urllib.parse import unquote
|
||||||
import requests
|
import requests
|
||||||
import _thread
|
import _thread
|
||||||
server = HTTPServer(('', 0), _now_imported)
|
server = HTTPServer(('', 0), _now_imported)
|
||||||
@@ -30,7 +31,7 @@ if _now_is_legacy:
|
|||||||
_thread.start_new_thread(server.handle_request, ())
|
_thread.start_new_thread(server.handle_request, ())
|
||||||
|
|
||||||
payload = json.loads(event['body'])
|
payload = json.loads(event['body'])
|
||||||
path = payload['path']
|
path = unquote(payload['path'])
|
||||||
headers = payload['headers']
|
headers = payload['headers']
|
||||||
method = payload['method']
|
method = payload['method']
|
||||||
encoding = payload.get('encoding')
|
encoding = payload.get('encoding')
|
||||||
@@ -53,10 +54,7 @@ if _now_is_legacy:
|
|||||||
else:
|
else:
|
||||||
print('using Web Server Gateway Interface (WSGI)')
|
print('using Web Server Gateway Interface (WSGI)')
|
||||||
import sys
|
import sys
|
||||||
try:
|
from urllib.parse import urlparse, unquote
|
||||||
from urllib.parse import urlparse
|
|
||||||
except ImportError:
|
|
||||||
from urlparse import urlparse
|
|
||||||
from werkzeug._compat import BytesIO
|
from werkzeug._compat import BytesIO
|
||||||
from werkzeug._compat import string_types
|
from werkzeug._compat import string_types
|
||||||
from werkzeug._compat import to_bytes
|
from werkzeug._compat import to_bytes
|
||||||
@@ -75,13 +73,14 @@ else:
|
|||||||
if isinstance(body, string_types):
|
if isinstance(body, string_types):
|
||||||
body = to_bytes(body, charset='utf-8')
|
body = to_bytes(body, charset='utf-8')
|
||||||
|
|
||||||
urlinfo = urlparse(payload['path'])
|
path = unquote(payload['path'])
|
||||||
|
query = urlparse(path).query
|
||||||
|
|
||||||
environ = {
|
environ = {
|
||||||
'CONTENT_LENGTH': str(len(body)),
|
'CONTENT_LENGTH': str(len(body)),
|
||||||
'CONTENT_TYPE': headers.get('content-type', ''),
|
'CONTENT_TYPE': headers.get('content-type', ''),
|
||||||
'PATH_INFO': payload['path'],
|
'PATH_INFO': path,
|
||||||
'QUERY_STRING': urlinfo.query,
|
'QUERY_STRING': query,
|
||||||
'REMOTE_ADDR': headers.get(
|
'REMOTE_ADDR': headers.get(
|
||||||
'x-forwarded-for', headers.get(
|
'x-forwarded-for', headers.get(
|
||||||
'x-real-ip', payload.get(
|
'x-real-ip', payload.get(
|
||||||
@@ -102,7 +101,7 @@ else:
|
|||||||
}
|
}
|
||||||
|
|
||||||
for key, value in environ.items():
|
for key, value in environ.items():
|
||||||
if isinstance(value, string_types):
|
if isinstance(value, string_types) and key != 'QUERY_STRING':
|
||||||
environ[key] = wsgi_encoding_dance(value)
|
environ[key] = wsgi_encoding_dance(value)
|
||||||
|
|
||||||
for key, value in headers.items():
|
for key, value in headers.items():
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/python",
|
"name": "@now/python",
|
||||||
"version": "0.2.1",
|
"version": "0.2.4",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
7
packages/now-python/test/fixtures/09-url-params/custom.py
vendored
Normal file
7
packages/now-python/test/fixtures/09-url-params/custom.py
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from flask import Flask, Response, __version__
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/', defaults={'path': ''})
|
||||||
|
@app.route('/<path:path>')
|
||||||
|
def catch_all(path):
|
||||||
|
return Response("path=%s" %(path), mimetype='text/html')
|
||||||
7
packages/now-python/test/fixtures/09-url-params/index.py
vendored
Normal file
7
packages/now-python/test/fixtures/09-url-params/index.py
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from flask import Flask, Response, __version__
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/', defaults={'path': ''})
|
||||||
|
@app.route('/<path:path>')
|
||||||
|
def catch_all(path):
|
||||||
|
return Response("path=%s" %(path), mimetype='text/html')
|
||||||
13
packages/now-python/test/fixtures/09-url-params/now.json
vendored
Normal file
13
packages/now-python/test/fixtures/09-url-params/now.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [
|
||||||
|
{ "src": "*.py", "use": "@now/python" }
|
||||||
|
],
|
||||||
|
"routes": [
|
||||||
|
{ "src": "/another", "dest": "custom.py" }
|
||||||
|
],
|
||||||
|
"probes": [
|
||||||
|
{ "path": "/?hello=/", "mustContain": "path=?hello=/" },
|
||||||
|
{ "path": "/another?hello=/", "mustContain": "path=another?hello=/" }
|
||||||
|
]
|
||||||
|
}
|
||||||
1
packages/now-python/test/fixtures/09-url-params/requirements.txt
vendored
Normal file
1
packages/now-python/test/fixtures/09-url-params/requirements.txt
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Flask==1.0.2
|
||||||
8
packages/now-python/test/fixtures/10-url-params-http-handler/custom.py
vendored
Normal file
8
packages/now-python/test/fixtures/10-url-params-http-handler/custom.py
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from http.server import BaseHTTPRequestHandler
|
||||||
|
|
||||||
|
class handler(BaseHTTPRequestHandler):
|
||||||
|
def do_GET(self):
|
||||||
|
self.send_response(200)
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(str("path=").encode()+self.path.encode())
|
||||||
|
return
|
||||||
8
packages/now-python/test/fixtures/10-url-params-http-handler/index.py
vendored
Normal file
8
packages/now-python/test/fixtures/10-url-params-http-handler/index.py
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from http.server import BaseHTTPRequestHandler
|
||||||
|
|
||||||
|
class handler(BaseHTTPRequestHandler):
|
||||||
|
def do_GET(self):
|
||||||
|
self.send_response(200)
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(str("path=").encode()+self.path.encode())
|
||||||
|
return
|
||||||
13
packages/now-python/test/fixtures/10-url-params-http-handler/now.json
vendored
Normal file
13
packages/now-python/test/fixtures/10-url-params-http-handler/now.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [
|
||||||
|
{ "src": "*.py", "use": "@now/python" }
|
||||||
|
],
|
||||||
|
"routes": [
|
||||||
|
{ "src": "/another", "dest": "custom.py" }
|
||||||
|
],
|
||||||
|
"probes": [
|
||||||
|
{ "path": "/?hello=/", "mustContain": "path=/?hello=/" },
|
||||||
|
{ "path": "/another?hello=/", "mustContain": "path=/another?hello=/" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -254,10 +254,10 @@ async function buildSingleFile({
|
|||||||
|
|
||||||
exports.build = async (m) => {
|
exports.build = async (m) => {
|
||||||
const {
|
const {
|
||||||
files, entrypoint, workPath, config,
|
files, entrypoint, workPath, config, meta,
|
||||||
} = m;
|
} = m;
|
||||||
console.log('downloading files');
|
console.log('downloading files');
|
||||||
const downloadedFiles = await download(files, workPath);
|
const downloadedFiles = await download(files, workPath, meta);
|
||||||
const entryPath = downloadedFiles[entrypoint].fsPath;
|
const entryPath = downloadedFiles[entrypoint].fsPath;
|
||||||
|
|
||||||
await installRust();
|
await installRust();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/rust",
|
"name": "@now/rust",
|
||||||
"version": "0.2.3",
|
"version": "0.2.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ exports.build = async ({
|
|||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to detect a server running on port ${devPort}`,
|
`Failed to detect a server running on port ${devPort}.\nDetails: https://err.sh/zeit/now-builders/now-static-build-failed-to-detect-a-server`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ exports.build = async ({
|
|||||||
}
|
}
|
||||||
routes.push({
|
routes.push({
|
||||||
src: `${srcBase}/(.*)`,
|
src: `${srcBase}/(.*)`,
|
||||||
dest: `http://localhost:${devPort}${srcBase}/$1`,
|
dest: `http://localhost:${devPort}/$1`,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (meta.isDev) {
|
if (meta.isDev) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/static-build",
|
"name": "@now/static-build",
|
||||||
"version": "0.5.5",
|
"version": "0.5.7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -28,11 +28,27 @@ async function runBuildLambda(inputPath) {
|
|||||||
entrypoint,
|
entrypoint,
|
||||||
config: build.config,
|
config: build.config,
|
||||||
});
|
});
|
||||||
console.log(analyzeResult);
|
|
||||||
const workPath = await getWritableDirectory();
|
const workPath = await getWritableDirectory();
|
||||||
const buildResult = await wrapper.build({
|
const buildResult = await wrapper.build({
|
||||||
files: inputFiles, entrypoint, config: build.config, workPath,
|
files: inputFiles,
|
||||||
|
entrypoint,
|
||||||
|
config: build.config,
|
||||||
|
workPath,
|
||||||
});
|
});
|
||||||
|
const { output } = buildResult;
|
||||||
|
|
||||||
|
// Windows support
|
||||||
|
if (output) {
|
||||||
|
buildResult.output = Object.keys(output).reduce(
|
||||||
|
(result, path) => ({
|
||||||
|
...result,
|
||||||
|
[path.replace(/\\/g, '/')]: output[path],
|
||||||
|
}),
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
analyzeResult,
|
analyzeResult,
|
||||||
buildResult,
|
buildResult,
|
||||||
|
|||||||
@@ -1135,10 +1135,10 @@
|
|||||||
globby "8.0.0"
|
globby "8.0.0"
|
||||||
signal-exit "3.0.2"
|
signal-exit "3.0.2"
|
||||||
|
|
||||||
"@zeit/ncc@0.18.2":
|
"@zeit/ncc@0.18.5":
|
||||||
version "0.18.2"
|
version "0.18.5"
|
||||||
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.18.2.tgz#b5f721ec1d23bfe531f3568633689ddab7c05638"
|
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.18.5.tgz#5687df6c32f1a2e2486aa110b3454ccebda4fb9c"
|
||||||
integrity sha512-liiuVTcxLaOIGQDftpZ2qhSS/vdEbuvmi2tkBWMfIwIyeKd/sh/jw+l8yONT3/unx/sSmfMTDnwfwUlY+saKiw==
|
integrity sha512-F+SbvEAh8rchiRXqQbmD1UmbePY7dCOKTbvfFtbVbK2xMH/tyri5YKfNxXKK7eL9EWkkbqB3NTVQO6nokApeBA==
|
||||||
|
|
||||||
JSONStream@^1.0.4, JSONStream@^1.3.4:
|
JSONStream@^1.0.4, JSONStream@^1.3.4:
|
||||||
version "1.3.5"
|
version "1.3.5"
|
||||||
|
|||||||
Reference in New Issue
Block a user