mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 12:57:46 +00:00
Compare commits
15 Commits
vercel@23.
...
@vercel/py
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e659eecf48 | ||
|
|
b428f7ff83 | ||
|
|
5eb133283d | ||
|
|
646c29600e | ||
|
|
469eb4315d | ||
|
|
6dc54d0d64 | ||
|
|
adc84d5148 | ||
|
|
88642b1ce8 | ||
|
|
4b8d207533 | ||
|
|
36fe5cc4d1 | ||
|
|
370b0dbed2 | ||
|
|
cc7a82fb0a | ||
|
|
6eea26c39e | ||
|
|
b8bfae7840 | ||
|
|
dc6a0a1cbb |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/build-utils",
|
||||
"version": "2.11.1-canary.0",
|
||||
"version": "2.11.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.js",
|
||||
@@ -29,7 +29,7 @@
|
||||
"@types/node-fetch": "^2.1.6",
|
||||
"@types/semver": "6.0.0",
|
||||
"@types/yazl": "^2.4.1",
|
||||
"@vercel/frameworks": "0.4.1-canary.0",
|
||||
"@vercel/frameworks": "0.4.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"aggregate-error": "3.0.1",
|
||||
"async-retry": "1.2.3",
|
||||
|
||||
1
packages/cgi/.gitignore
vendored
1
packages/cgi/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
handler
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
const execa = require('execa');
|
||||
const { join } = require('path');
|
||||
const { homedir } = require('os');
|
||||
|
||||
async function main() {
|
||||
process.env.GOOS = 'linux';
|
||||
process.env.GOARCH = 'amd64';
|
||||
process.env.GOPATH = join(homedir(), 'go');
|
||||
|
||||
await execa('go', ['get', 'github.com/aws/aws-lambda-go/events'], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
await execa('go', ['get', 'github.com/aws/aws-lambda-go/lambda'], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
await execa('go', ['build', '-o', 'handler', 'main.go'], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,45 +0,0 @@
|
||||
const path = require('path');
|
||||
const { mkdirp, copyFile } = require('fs-extra');
|
||||
|
||||
const {
|
||||
glob,
|
||||
download,
|
||||
shouldServe,
|
||||
createLambda,
|
||||
getWritableDirectory,
|
||||
} = require('@vercel/build-utils');
|
||||
|
||||
exports.analyze = ({ files, entrypoint }) => files[entrypoint].digest;
|
||||
|
||||
exports.version = 3;
|
||||
|
||||
exports.build = async ({ workPath, files, entrypoint, meta }) => {
|
||||
const outDir = await getWritableDirectory();
|
||||
|
||||
await download(files, workPath, meta);
|
||||
|
||||
const handlerPath = path.join(__dirname, 'handler');
|
||||
await copyFile(handlerPath, path.join(outDir, 'handler'));
|
||||
|
||||
const entrypointOutDir = path.join(outDir, path.dirname(entrypoint));
|
||||
await mkdirp(entrypointOutDir);
|
||||
|
||||
// For now only the entrypoint file is copied into the lambda
|
||||
await copyFile(
|
||||
path.join(workPath, entrypoint),
|
||||
path.join(outDir, entrypoint)
|
||||
);
|
||||
|
||||
const lambda = await createLambda({
|
||||
files: await glob('**', outDir),
|
||||
handler: 'handler',
|
||||
runtime: 'go1.x',
|
||||
environment: {
|
||||
SCRIPT_FILENAME: entrypoint,
|
||||
},
|
||||
});
|
||||
|
||||
return { output: lambda };
|
||||
};
|
||||
|
||||
exports.shouldServe = shouldServe;
|
||||
@@ -1,36 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
now "../../utils/go/bridge"
|
||||
"net/http"
|
||||
"net/http/cgi"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type CgiHandler struct {
|
||||
http.Handler
|
||||
Dir string
|
||||
Script string
|
||||
}
|
||||
|
||||
func (h *CgiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
handler := cgi.Handler{
|
||||
Path: h.Script,
|
||||
Root: "/" + h.Script,
|
||||
Dir: h.Dir,
|
||||
Env: []string{
|
||||
"HTTPS=on",
|
||||
"SERVER_PORT=443",
|
||||
"SERVER_SOFTWARE=@vercel/cgi",
|
||||
},
|
||||
}
|
||||
handler.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func main() {
|
||||
workdir, _ := filepath.Abs(".")
|
||||
script := os.Getenv("SCRIPT_FILENAME")
|
||||
handler := &CgiHandler{nil, workdir, script}
|
||||
now.Start(handler)
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"name": "@vercel/cgi",
|
||||
"version": "1.0.7",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/vercel/vercel.git",
|
||||
"directory": "packages/cgi"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node build",
|
||||
"prepublishOnly": "node build"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"handler"
|
||||
],
|
||||
"dependencies": {
|
||||
"fs-extra": "7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rmfr": "2.0.0"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vercel",
|
||||
"version": "23.0.1-canary.1",
|
||||
"version": "23.0.1",
|
||||
"preferGlobal": true,
|
||||
"license": "Apache-2.0",
|
||||
"description": "The command-line interface for Vercel",
|
||||
@@ -61,10 +61,10 @@
|
||||
"node": ">= 12"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.11.1-canary.0",
|
||||
"@vercel/build-utils": "2.11.1",
|
||||
"@vercel/go": "1.2.2",
|
||||
"@vercel/node": "1.11.0",
|
||||
"@vercel/python": "2.0.4-canary.0",
|
||||
"@vercel/node": "1.11.1",
|
||||
"@vercel/python": "2.0.4",
|
||||
"@vercel/ruby": "1.2.6",
|
||||
"update-notifier": "4.1.0"
|
||||
},
|
||||
@@ -100,7 +100,7 @@
|
||||
"@types/universal-analytics": "0.4.2",
|
||||
"@types/which": "1.3.2",
|
||||
"@types/write-json-file": "2.2.1",
|
||||
"@vercel/frameworks": "0.4.1-canary.0",
|
||||
"@vercel/frameworks": "0.4.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@zeit/fun": "0.11.2",
|
||||
"@zeit/source-map-support": "0.6.2",
|
||||
@@ -148,7 +148,7 @@
|
||||
"node-fetch": "2.6.1",
|
||||
"npm-package-arg": "6.1.0",
|
||||
"nyc": "13.2.0",
|
||||
"open": "8.0.2",
|
||||
"open": "8.2.0",
|
||||
"ora": "3.4.0",
|
||||
"pcre-to-regexp": "1.0.0",
|
||||
"pluralize": "7.0.0",
|
||||
|
||||
@@ -2,10 +2,11 @@ import chalk from 'chalk';
|
||||
|
||||
import { handleError } from '../../util/error';
|
||||
|
||||
import Client from '../../util/client';
|
||||
import getArgs from '../../util/get-args';
|
||||
import getSubcommand from '../../util/get-subcommand';
|
||||
import logo from '../../util/output/logo';
|
||||
import { getPkgName } from '../../util/pkg-name.ts';
|
||||
import { getPkgName } from '../../util/pkg-name';
|
||||
|
||||
import ls from './ls';
|
||||
import rm from './rm';
|
||||
@@ -36,6 +37,7 @@ const help = () => {
|
||||
)} Login token
|
||||
-S, --scope Set a custom scope
|
||||
-N, --next Show next page of results
|
||||
|
||||
${chalk.dim('Examples:')}
|
||||
|
||||
${chalk.gray('–')} Add a new alias to ${chalk.underline('my-api.vercel.app')}
|
||||
@@ -64,13 +66,13 @@ const help = () => {
|
||||
};
|
||||
|
||||
const COMMAND_CONFIG = {
|
||||
default: 'set',
|
||||
default: ['set'],
|
||||
ls: ['ls', 'list'],
|
||||
rm: ['rm', 'remove'],
|
||||
set: ['set'],
|
||||
};
|
||||
|
||||
export default async function main(client) {
|
||||
export default async function main(client: Client) {
|
||||
let argv;
|
||||
|
||||
try {
|
||||
@@ -1,21 +1,26 @@
|
||||
import chalk from 'chalk';
|
||||
import ms from 'ms';
|
||||
import table from 'text-table';
|
||||
import Now from '../../util';
|
||||
import Client from '../../util/client';
|
||||
import getAliases from '../../util/alias/get-aliases';
|
||||
import getScope from '../../util/get-scope.ts';
|
||||
import stamp from '../../util/output/stamp.ts';
|
||||
import strlen from '../../util/strlen.ts';
|
||||
import getScope from '../../util/get-scope';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import strlen from '../../util/strlen';
|
||||
import getCommandFlags from '../../util/get-command-flags';
|
||||
import { getCommandName } from '../../util/pkg-name.ts';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
export default async function ls(client, opts, args) {
|
||||
const {
|
||||
apiUrl,
|
||||
authConfig: { token },
|
||||
output,
|
||||
config: { currentTeam },
|
||||
} = client;
|
||||
import { Alias } from '../../types';
|
||||
|
||||
interface Options {
|
||||
'--next'?: number;
|
||||
}
|
||||
|
||||
export default async function ls(
|
||||
client: Client,
|
||||
opts: Options,
|
||||
args: string[]
|
||||
) {
|
||||
const { output } = client;
|
||||
const { '--next': nextTimestamp } = opts;
|
||||
|
||||
let contextName = null;
|
||||
@@ -36,13 +41,6 @@ export default async function ls(client, opts, args) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const now = new Now({
|
||||
apiUrl,
|
||||
token,
|
||||
debug: client.output.isDebugEnabled(),
|
||||
currentTeam,
|
||||
output,
|
||||
});
|
||||
const lsStamp = stamp();
|
||||
|
||||
if (args.length > 0) {
|
||||
@@ -56,8 +54,9 @@ export default async function ls(client, opts, args) {
|
||||
|
||||
output.spinner(`Fetching aliases under ${chalk.bold(contextName)}`);
|
||||
|
||||
// Get the list of alias
|
||||
const { aliases, pagination } = await getAliases(
|
||||
now,
|
||||
client,
|
||||
undefined,
|
||||
nextTimestamp
|
||||
);
|
||||
@@ -73,21 +72,20 @@ export default async function ls(client, opts, args) {
|
||||
);
|
||||
}
|
||||
|
||||
now.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
function printAliasTable(aliases) {
|
||||
function printAliasTable(aliases: Alias[]) {
|
||||
return `${table(
|
||||
[
|
||||
['source', 'url', 'age'].map(h => chalk.gray(h)),
|
||||
['source', 'url', 'age'].map(header => chalk.gray(header)),
|
||||
...aliases.map(a => [
|
||||
// for legacy reasons, we might have situations
|
||||
// where the deployment was deleted and the alias
|
||||
// not collected appropriately, and we need to handle it
|
||||
a.deployment && a.deployment.url ? a.deployment.url : chalk.gray('–'),
|
||||
a.alias,
|
||||
ms(Date.now() - new Date(a.createdAt)),
|
||||
ms(Date.now() - a.createdAt),
|
||||
]),
|
||||
],
|
||||
{
|
||||
@@ -1,23 +1,29 @@
|
||||
import chalk from 'chalk';
|
||||
import ms from 'ms';
|
||||
import table from 'text-table';
|
||||
import Now from '../../util';
|
||||
import getScope from '../../util/get-scope.ts';
|
||||
import Client from '../../util/client';
|
||||
import getScope from '../../util/get-scope';
|
||||
import removeAliasById from '../../util/alias/remove-alias-by-id';
|
||||
import stamp from '../../util/output/stamp.ts';
|
||||
import strlen from '../../util/strlen.ts';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import strlen from '../../util/strlen';
|
||||
import confirm from '../../util/input/confirm';
|
||||
import { isValidName } from '../../util/is-valid-name';
|
||||
import findAliasByAliasOrId from '../../util/alias/find-alias-by-alias-or-id';
|
||||
import { getCommandName } from '../../util/pkg-name.ts';
|
||||
|
||||
export default async function rm(client, opts, args) {
|
||||
const {
|
||||
apiUrl,
|
||||
authConfig: { token },
|
||||
output,
|
||||
config: { currentTeam },
|
||||
} = client;
|
||||
import { Alias } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import { isValidName } from '../../util/is-valid-name';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
type Options = {
|
||||
'--yes': boolean;
|
||||
};
|
||||
|
||||
export default async function rm(
|
||||
client: Client,
|
||||
opts: Partial<Options>,
|
||||
args: string[]
|
||||
) {
|
||||
const { output } = client;
|
||||
|
||||
let contextName = null;
|
||||
|
||||
@@ -32,13 +38,6 @@ export default async function rm(client, opts, args) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
const now = new Now({
|
||||
apiUrl,
|
||||
token,
|
||||
debug: client.output.isDebugEnabled(),
|
||||
currentTeam,
|
||||
output,
|
||||
});
|
||||
const [aliasOrId] = args;
|
||||
|
||||
if (args.length !== 1) {
|
||||
@@ -61,7 +60,8 @@ export default async function rm(client, opts, args) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const alias = await findAliasByAliasOrId(output, now, aliasOrId);
|
||||
const alias = await findAliasByAliasOrId(output, client, aliasOrId);
|
||||
|
||||
if (!alias) {
|
||||
output.error(
|
||||
`Alias not found by "${aliasOrId}" under ${chalk.bold(contextName)}`
|
||||
@@ -76,7 +76,7 @@ export default async function rm(client, opts, args) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
await removeAliasById(now, alias.uid);
|
||||
await removeAliasById(client, alias.uid);
|
||||
console.log(
|
||||
`${chalk.cyan('> Success!')} Alias ${chalk.bold(
|
||||
alias.alias
|
||||
@@ -85,7 +85,7 @@ export default async function rm(client, opts, args) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
async function confirmAliasRemove(output, alias) {
|
||||
async function confirmAliasRemove(output: Output, alias: Alias) {
|
||||
const srcUrl = alias.deployment
|
||||
? chalk.underline(alias.deployment.url)
|
||||
: null;
|
||||
@@ -94,7 +94,7 @@ async function confirmAliasRemove(output, alias) {
|
||||
[
|
||||
...(srcUrl ? [srcUrl] : []),
|
||||
chalk.underline(alias.alias),
|
||||
chalk.gray(`${ms(new Date() - new Date(alias.created))} ago`),
|
||||
chalk.gray(`${ms(Date.now() - alias.createdAt)} ago`),
|
||||
],
|
||||
],
|
||||
{
|
||||
@@ -28,7 +28,7 @@ type Options = {
|
||||
|
||||
export default async function set(
|
||||
client: Client,
|
||||
opts: Options,
|
||||
opts: Partial<Options>,
|
||||
args: string[]
|
||||
) {
|
||||
const { output, localConfig } = client;
|
||||
|
||||
@@ -12,7 +12,6 @@ import { getCommandName, getPkgName } from '../util/pkg-name';
|
||||
import getGlobalPathConfig from '../util/config/global-path';
|
||||
import { writeToAuthConfigFile, writeToConfigFile } from '../util/config/files';
|
||||
import Client from '../util/client';
|
||||
import { LoginParams } from '../util/login/types';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
@@ -46,7 +45,7 @@ const help = () => {
|
||||
|
||||
export default async function login(client: Client): Promise<number> {
|
||||
let argv;
|
||||
const { apiUrl, output } = client;
|
||||
const { output } = client;
|
||||
|
||||
try {
|
||||
argv = getArgs(client.argv.slice(2));
|
||||
@@ -68,18 +67,17 @@ export default async function login(client: Client): Promise<number> {
|
||||
const input = argv._[1];
|
||||
|
||||
let result: number | string = 1;
|
||||
const params: LoginParams = { output, apiUrl };
|
||||
|
||||
if (input) {
|
||||
// Email or Team slug was provided via command line
|
||||
if (validateEmail(input)) {
|
||||
result = await doEmailLogin(params, input);
|
||||
result = await doEmailLogin(client, input);
|
||||
} else {
|
||||
result = await doSsoLogin(params, input);
|
||||
result = await doSsoLogin(client, input);
|
||||
}
|
||||
} else {
|
||||
// Interactive mode
|
||||
result = await prompt(params);
|
||||
result = await prompt(client);
|
||||
}
|
||||
|
||||
// The login function failed, so it returned an exit code
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import chalk from 'chalk';
|
||||
import logo from '../util/output/logo';
|
||||
// @ts-ignore
|
||||
import { handleError } from '../util/error';
|
||||
import { writeToConfigFile, writeToAuthConfigFile } from '../util/config/files';
|
||||
import getArgs from '../util/get-args';
|
||||
@@ -62,6 +61,7 @@ export default async function main(client: Client): Promise<number> {
|
||||
try {
|
||||
await client.fetch(`/v3/user/tokens/current`, {
|
||||
method: 'DELETE',
|
||||
useCurrentTeam: false,
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.status === 403) {
|
||||
|
||||
@@ -16,7 +16,7 @@ export interface JSONObject {
|
||||
}
|
||||
|
||||
export interface AuthConfig {
|
||||
token: string;
|
||||
token?: string;
|
||||
skipWrite?: boolean;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ export type Deployment = {
|
||||
export type Alias = {
|
||||
uid: string;
|
||||
alias: string;
|
||||
created: string;
|
||||
createdAt: number;
|
||||
deployment: {
|
||||
id: string;
|
||||
url: string;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Output } from '../output';
|
||||
import { Alias } from '../../types';
|
||||
|
||||
import Client from '../client';
|
||||
|
||||
export default async function findAliasByAliasOrId(
|
||||
@@ -11,7 +12,6 @@ export default async function findAliasByAliasOrId(
|
||||
`/now/aliases/${encodeURIComponent(getSafeAlias(aliasOrId))}`
|
||||
);
|
||||
}
|
||||
|
||||
function getSafeAlias(alias: string) {
|
||||
return alias
|
||||
.replace(/^https:\/\//i, '')
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Alias } from '../../types';
|
||||
import { Alias, PaginationOptions } from '../../types';
|
||||
import Client from '../client';
|
||||
|
||||
type Response = {
|
||||
aliases: Alias[];
|
||||
pagination: PaginationOptions;
|
||||
};
|
||||
|
||||
export default async function getAliases(
|
||||
|
||||
@@ -2,6 +2,6 @@ import Client from '../client';
|
||||
|
||||
export default async function removeAliasById(client: Client, id: string) {
|
||||
return client.fetch(`/now/aliases/${id}`, {
|
||||
method: 'DELETE'
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -145,6 +145,7 @@ export default class DevServer {
|
||||
private devServerPids: Set<number>;
|
||||
private projectSettings?: ProjectSettings;
|
||||
|
||||
private vercelConfigWarning: boolean;
|
||||
private getVercelConfigPromise: Promise<VercelConfig> | null;
|
||||
private blockingBuildsPromise: Promise<void> | null;
|
||||
private updateBuildersPromise: Promise<void> | null;
|
||||
@@ -181,6 +182,7 @@ export default class DevServer {
|
||||
this.inProgressBuilds = new Map();
|
||||
this.devCacheDir = join(getVercelDirectory(cwd), 'cache');
|
||||
|
||||
this.vercelConfigWarning = false;
|
||||
this.getVercelConfigPromise = null;
|
||||
this.blockingBuildsPromise = null;
|
||||
this.updateBuildersPromise = null;
|
||||
@@ -636,6 +638,20 @@ export default class DevServer {
|
||||
|
||||
await this.validateVercelConfig(config);
|
||||
|
||||
// TODO: temporarily strip and warn since `has` is not implemented yet
|
||||
config.routes = (config.routes || []).filter(route => {
|
||||
if ('has' in route) {
|
||||
if (!this.vercelConfigWarning) {
|
||||
this.vercelConfigWarning = true;
|
||||
this.output.warn(
|
||||
`The "has" property in ${config[fileNameSymbol]} will be ignored during development. Deployments will work as expected.`
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
this.caseSensitive = hasNewRoutingProperties(config);
|
||||
this.apiDir = detectApiDirectory(config.builds || []);
|
||||
this.apiExtensions = detectApiExtensions(config.builds || []);
|
||||
|
||||
@@ -42,7 +42,7 @@ export default async function doEmailLogin(
|
||||
while (!token) {
|
||||
try {
|
||||
await sleep(ms('1s'));
|
||||
token = await verify(email, verificationToken, params);
|
||||
token = await verify(email, verificationToken, 'Email', params);
|
||||
} catch (err) {
|
||||
if (err.message !== 'Confirmation incomplete') {
|
||||
output.error(err.message);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { hostname } from 'os';
|
||||
import { InvalidEmail, AccountNotFound } from '../errors-ts';
|
||||
import ua from '../ua';
|
||||
import { getTitleName } from '../pkg-name';
|
||||
import { LoginData } from './types';
|
||||
|
||||
export default async function login(
|
||||
@@ -10,20 +8,13 @@ export default async function login(
|
||||
email: string,
|
||||
mode: 'login' | 'signup' = 'login'
|
||||
): Promise<LoginData> {
|
||||
const hyphens = new RegExp('-', 'g');
|
||||
const host = hostname().replace(hyphens, ' ').replace('.local', '');
|
||||
const tokenName = `${getTitleName()} CLI on ${host}`;
|
||||
|
||||
const response = await fetch(`${apiUrl}/now/registration?mode=${mode}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'User-Agent': ua,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
tokenName,
|
||||
email,
|
||||
}),
|
||||
body: JSON.stringify({ email }),
|
||||
});
|
||||
|
||||
const body = await response.json();
|
||||
|
||||
@@ -2,12 +2,12 @@ import http from 'http';
|
||||
import open from 'open';
|
||||
import { URL } from 'url';
|
||||
import listen from 'async-listen';
|
||||
import { hostname } from 'os';
|
||||
import { LoginParams } from './types';
|
||||
import prompt from './prompt';
|
||||
import verify from './verify';
|
||||
import { getTitleName } from '../pkg-name';
|
||||
import highlight from '../output/highlight';
|
||||
import link from '../output/link';
|
||||
import eraseLines from '../output/erase-lines';
|
||||
|
||||
export default async function doOauthLogin(
|
||||
params: LoginParams,
|
||||
@@ -16,21 +16,15 @@ export default async function doOauthLogin(
|
||||
): Promise<number | string> {
|
||||
const { output } = params;
|
||||
|
||||
output.spinner(
|
||||
`Please complete the ${provider} authentication in your web browser`
|
||||
);
|
||||
|
||||
const server = http.createServer();
|
||||
const address = await listen(server, 0, '127.0.0.1');
|
||||
const { port } = new URL(address);
|
||||
url.searchParams.append('mode', 'login');
|
||||
url.searchParams.append('next', `http://localhost:${port}`);
|
||||
url.searchParams.set('mode', 'login');
|
||||
url.searchParams.set('next', `http://localhost:${port}`);
|
||||
|
||||
// Append token name param
|
||||
const hyphens = new RegExp('-', 'g');
|
||||
const host = hostname().replace(hyphens, ' ').replace('.local', '');
|
||||
const tokenName = `${getTitleName()} CLI on ${host} via ${provider}`;
|
||||
url.searchParams.append('tokenName', tokenName);
|
||||
output.log(`Please visit the following URL in your web browser:`);
|
||||
output.log(link(url.href));
|
||||
output.spinner(`Waiting for ${provider} authentication to be completed`);
|
||||
|
||||
try {
|
||||
const [query] = await Promise.all([
|
||||
@@ -78,6 +72,9 @@ export default async function doOauthLogin(
|
||||
open(url.href),
|
||||
]);
|
||||
|
||||
output.stopSpinner();
|
||||
output.print(eraseLines(3));
|
||||
|
||||
const loginError = query.get('loginError');
|
||||
if (loginError) {
|
||||
const err = JSON.parse(loginError);
|
||||
@@ -106,7 +103,7 @@ export default async function doOauthLogin(
|
||||
}
|
||||
|
||||
output.spinner('Verifying authentication token');
|
||||
const token = await verify(email, verificationToken, params);
|
||||
const token = await verify(email, verificationToken, provider, params);
|
||||
output.success(
|
||||
`${provider} authentication complete for ${highlight(email)}`
|
||||
);
|
||||
|
||||
@@ -4,6 +4,6 @@ import doOauthLogin from './oauth';
|
||||
|
||||
export default function doSsoLogin(params: LoginParams, teamIdOrSlug: string) {
|
||||
const url = new URL('/auth/sso', params.apiUrl);
|
||||
url.searchParams.append('teamId', teamIdOrSlug);
|
||||
url.searchParams.set('teamId', teamIdOrSlug);
|
||||
return doOauthLogin(params, url, 'SAML Single Sign-On');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { AuthConfig } from '../../types';
|
||||
import { Output } from '../output';
|
||||
|
||||
export interface LoginParams {
|
||||
authConfig: AuthConfig;
|
||||
apiUrl: string;
|
||||
output: Output;
|
||||
ssoUserId?: string;
|
||||
|
||||
@@ -1,24 +1,41 @@
|
||||
import { URL } from 'url';
|
||||
import fetch from 'node-fetch';
|
||||
import fetch, { Headers } from 'node-fetch';
|
||||
import ua from '../ua';
|
||||
import { LoginParams } from './types';
|
||||
import { hostname } from 'os';
|
||||
import { getTitleName } from '../pkg-name';
|
||||
|
||||
export default async function verify(
|
||||
email: string,
|
||||
verificationToken: string,
|
||||
{ apiUrl, ssoUserId }: LoginParams
|
||||
provider: string,
|
||||
{ authConfig, apiUrl, ssoUserId }: LoginParams
|
||||
): Promise<string> {
|
||||
const url = new URL('/registration/verify', apiUrl);
|
||||
url.searchParams.append('email', email);
|
||||
url.searchParams.append('token', verificationToken);
|
||||
if (ssoUserId) {
|
||||
url.searchParams.append('ssoUserId', ssoUserId);
|
||||
url.searchParams.set('email', email);
|
||||
url.searchParams.set('token', verificationToken);
|
||||
|
||||
const headers = new Headers({ 'User-Agent': ua });
|
||||
|
||||
if (authConfig.token) {
|
||||
// If there is already an auth token then it will be
|
||||
// upgraded, rather than a new token being created
|
||||
headers.set('Authorization', `Bearer ${authConfig.token}`);
|
||||
} else {
|
||||
// Set the "name" of the Token that will be created
|
||||
const hyphens = new RegExp('-', 'g');
|
||||
const host = hostname().replace(hyphens, ' ').replace('.local', '');
|
||||
const tokenName = `${getTitleName()} CLI on ${host} via ${provider}`;
|
||||
url.searchParams.set('tokenName', tokenName);
|
||||
}
|
||||
|
||||
const res = await fetch(url.href, {
|
||||
headers: { 'User-Agent': ua },
|
||||
});
|
||||
// If `ssoUserId` is defined then this verification
|
||||
// will complete the SAML two-step login connection
|
||||
if (ssoUserId) {
|
||||
url.searchParams.set('ssoUserId', ssoUserId);
|
||||
}
|
||||
|
||||
const res = await fetch(url.href, { headers });
|
||||
const body = await res.json();
|
||||
|
||||
if (!res.ok) {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 78 KiB |
@@ -1710,7 +1710,9 @@ test(
|
||||
expectHeader('image/svg+xml'),
|
||||
fetchOpts('image/webp')
|
||||
);
|
||||
// bmp should bypass: serve as-is
|
||||
/* Disabled bmp because `next dev` bypasses
|
||||
* and production will convert. Eventually
|
||||
* we can enable once `next dev` supports it.
|
||||
await testPath(
|
||||
200,
|
||||
toUrl('/test.bmp', 64, 50),
|
||||
@@ -1718,6 +1720,7 @@ test(
|
||||
expectHeader('image/bmp'),
|
||||
fetchOpts('image/webp')
|
||||
);
|
||||
*/
|
||||
// animated gif should bypass: serve as-is
|
||||
await testPath(
|
||||
200,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/client",
|
||||
"version": "10.1.1-canary.0",
|
||||
"version": "10.1.1",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"homepage": "https://vercel.com",
|
||||
@@ -40,7 +40,7 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.11.1-canary.0",
|
||||
"@vercel/build-utils": "2.11.1",
|
||||
"@zeit/fetch": "5.2.0",
|
||||
"async-retry": "1.2.3",
|
||||
"async-sema": "3.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/frameworks",
|
||||
"version": "0.4.1-canary.0",
|
||||
"version": "0.4.1",
|
||||
"main": "./dist/frameworks.js",
|
||||
"types": "./dist/frameworks.d.ts",
|
||||
"files": [
|
||||
@@ -20,7 +20,7 @@
|
||||
"@types/js-yaml": "3.12.1",
|
||||
"@types/node": "12.0.4",
|
||||
"@types/node-fetch": "2.5.8",
|
||||
"@vercel/routing-utils": "1.11.2-canary.0",
|
||||
"@vercel/routing-utils": "1.11.2",
|
||||
"ajv": "6.12.2",
|
||||
"jest": "24.9.0",
|
||||
"ts-jest": "24.1.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/node",
|
||||
"version": "1.11.0",
|
||||
"version": "1.11.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
||||
@@ -33,7 +33,7 @@
|
||||
"@types/etag": "1.8.0",
|
||||
"@types/test-listen": "1.1.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@vercel/nft": "0.12.2",
|
||||
"@vercel/nft": "0.13.1",
|
||||
"content-type": "1.0.4",
|
||||
"cookie": "0.4.0",
|
||||
"etag": "1.8.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/python",
|
||||
"version": "2.0.4-canary.0",
|
||||
"version": "2.0.4",
|
||||
"main": "./dist/index.js",
|
||||
"license": "MIT",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/routing-utils",
|
||||
"version": "1.11.2-canary.0",
|
||||
"version": "1.11.2",
|
||||
"description": "Vercel routing utilities",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@@ -37,7 +37,7 @@ function getCheckAndContinue(
|
||||
route
|
||||
)}`
|
||||
);
|
||||
} else if (route.check) {
|
||||
} else if (route.check && !route.override) {
|
||||
checks.push(route);
|
||||
} else if (route.continue && !route.override) {
|
||||
continues.push(route);
|
||||
|
||||
49
packages/routing-utils/test/merge.spec.js
vendored
49
packages/routing-utils/test/merge.spec.js
vendored
@@ -420,7 +420,7 @@ test('mergeRoutes ensure `handle: error` comes last', () => {
|
||||
deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('mergeRoutes ensure beforeFiles comes after redirects', () => {
|
||||
test('mergeRoutes ensure beforeFiles comes after redirects (continue)', () => {
|
||||
const userRoutes = [];
|
||||
const builds = [
|
||||
{
|
||||
@@ -466,3 +466,50 @@ test('mergeRoutes ensure beforeFiles comes after redirects', () => {
|
||||
];
|
||||
deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('mergeRoutes ensure beforeFiles comes after redirects (check)', () => {
|
||||
const userRoutes = [];
|
||||
const builds = [
|
||||
{
|
||||
use: '@vercel/next',
|
||||
entrypoint: 'package.json',
|
||||
routes: [
|
||||
{
|
||||
src: '^/home$',
|
||||
status: 301,
|
||||
headers: {
|
||||
Location: '/',
|
||||
},
|
||||
},
|
||||
{
|
||||
src: '^/hello$',
|
||||
dest: '/somewhere',
|
||||
check: true,
|
||||
override: true,
|
||||
},
|
||||
{
|
||||
handle: 'filesystem',
|
||||
},
|
||||
{
|
||||
src: '^/404$',
|
||||
dest: '/404',
|
||||
status: 404,
|
||||
check: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
const actual = mergeRoutes({ userRoutes, builds });
|
||||
const expected = [
|
||||
{ src: '^/home$', status: 301, headers: { Location: '/' } },
|
||||
{
|
||||
src: '^/hello$',
|
||||
dest: '/somewhere',
|
||||
check: true,
|
||||
override: true,
|
||||
},
|
||||
{ handle: 'filesystem' },
|
||||
{ src: '^/404$', dest: '/404', status: 404, check: true },
|
||||
];
|
||||
deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
package bridge
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"github.com/aws/aws-lambda-go/events"
|
||||
"github.com/aws/aws-lambda-go/lambda"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
Host string `json:"host"`
|
||||
Path string `json:"path"`
|
||||
Method string `json:"method"`
|
||||
Headers map[string]string `json:"headers"`
|
||||
Encoding string `json:"encoding,omitempty"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
StatusCode int `json:"statusCode"`
|
||||
Headers map[string][]string `json:"headers"`
|
||||
Encoding string `json:"encoding,omitemtpy"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
type ResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
statusCode int
|
||||
headers http.Header
|
||||
body *bytes.Buffer
|
||||
}
|
||||
|
||||
func (w *ResponseWriter) Header() http.Header {
|
||||
return w.headers
|
||||
}
|
||||
|
||||
func (w *ResponseWriter) Write(p []byte) (n int, err error) {
|
||||
n, err = w.body.Write(p)
|
||||
return
|
||||
}
|
||||
|
||||
func (w *ResponseWriter) WriteHeader(statusCode int) {
|
||||
w.statusCode = statusCode
|
||||
}
|
||||
|
||||
var userHandler http.Handler
|
||||
|
||||
func Serve(handler http.Handler, req *Request) (res Response, err error) {
|
||||
var body []byte
|
||||
if req.Encoding == "base64" {
|
||||
body, err = base64.StdEncoding.DecodeString(req.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
body = []byte(req.Body)
|
||||
}
|
||||
|
||||
r, err := http.NewRequest(req.Method, req.Path, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range req.Headers {
|
||||
r.Header.Add(k, v)
|
||||
switch strings.ToLower(k) {
|
||||
case "host":
|
||||
// we need to set `Host` in the request
|
||||
// because Go likes to ignore the `Host` header
|
||||
// see https://github.com/golang/go/issues/7682
|
||||
r.Host = v
|
||||
case "content-length":
|
||||
contentLength, _ := strconv.ParseInt(v, 10, 64)
|
||||
r.ContentLength = contentLength
|
||||
case "x-forwarded-for":
|
||||
case "x-real-ip":
|
||||
r.RemoteAddr = v
|
||||
}
|
||||
}
|
||||
|
||||
var bodyBuf bytes.Buffer
|
||||
w := &ResponseWriter{
|
||||
nil,
|
||||
http.StatusOK,
|
||||
make(http.Header),
|
||||
&bodyBuf,
|
||||
}
|
||||
|
||||
handler.ServeHTTP(w, r)
|
||||
defer r.Body.Close()
|
||||
|
||||
headers := make(map[string][]string)
|
||||
for k, v := range w.headers {
|
||||
for _, s := range v {
|
||||
headers[k] = append(headers[k], s)
|
||||
}
|
||||
}
|
||||
|
||||
res = Response{
|
||||
StatusCode: w.statusCode,
|
||||
Headers: headers,
|
||||
Encoding: "base64",
|
||||
Body: base64.StdEncoding.EncodeToString(bodyBuf.Bytes()),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Maps the `APIGatewayProxyRequest` to a `Request` instance and invokes `Serve()`
|
||||
func handler(event events.APIGatewayProxyRequest) (res Response, err error) {
|
||||
var req Request
|
||||
err = json.Unmarshal([]byte(event.Body), &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res, err = Serve(userHandler, &req)
|
||||
return
|
||||
}
|
||||
|
||||
// Starts the Lambda
|
||||
func Start(h http.Handler) {
|
||||
userHandler = h
|
||||
lambda.Start(handler)
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package bridge
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type HttpHandler struct {
|
||||
http.Handler
|
||||
t *testing.T
|
||||
}
|
||||
|
||||
func (h *HttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("X-Foo", "bar")
|
||||
w.WriteHeader(404)
|
||||
w.Write([]byte("test"))
|
||||
}
|
||||
|
||||
func TestServe(t *testing.T) {
|
||||
h := &HttpHandler{nil, t}
|
||||
req := &Request{
|
||||
"test.com",
|
||||
"/path?foo=bar",
|
||||
"POST",
|
||||
map[string]string{"Content-Length": "1", "X-Foo": "bar"},
|
||||
"",
|
||||
"a",
|
||||
}
|
||||
res, err := Serve(h, req)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
if res.StatusCode != 404 {
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Printf("status code: %d\n", res.StatusCode)
|
||||
fmt.Printf("header: %v\n", res.Headers)
|
||||
fmt.Printf("base64 body: %s\n", res.Body)
|
||||
body, err := base64.StdEncoding.DecodeString(res.Body)
|
||||
fmt.Printf("body: %s\n", body)
|
||||
}
|
||||
1
utils/run.js
vendored
1
utils/run.js
vendored
@@ -6,7 +6,6 @@ const allPackages = [
|
||||
'routing-utils',
|
||||
'frameworks',
|
||||
'build-utils',
|
||||
'cgi',
|
||||
'client',
|
||||
'node-bridge',
|
||||
'node',
|
||||
|
||||
26
yarn.lock
26
yarn.lock
@@ -2116,13 +2116,13 @@
|
||||
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.24.0.tgz#a2e8783a185caa99b5d8961a57dfc9665de16296"
|
||||
integrity sha512-crqItMcIwCkvdXY/V3/TzrHJQx6nbIaRqE1cOopJhgGX6izvNov40SmD//nS5flfEvdK54YGjwVVq+zG6crjOg==
|
||||
|
||||
"@vercel/nft@0.12.2":
|
||||
version "0.12.2"
|
||||
resolved "https://registry.yarnpkg.com/@vercel/nft/-/nft-0.12.2.tgz#67ea9f231d24639b3783e3e69bef173659972d3b"
|
||||
integrity sha512-H8n44GboVnJaVVX4+WfuOTAaNLDnUIYH4KpMZcXll7KMNIcg0JTd0IFRsIBe/uvuXisqm6nEANp8Tr3/1dlRQw==
|
||||
"@vercel/nft@0.13.1":
|
||||
version "0.13.1"
|
||||
resolved "https://registry.yarnpkg.com/@vercel/nft/-/nft-0.13.1.tgz#98df07e04620069ba63fff92af490c5842a2f31f"
|
||||
integrity sha512-7pBTfSkwhhcPAeGVsFml5YX7LCZgtocP+zTAknnRK2u/RsV3GGqOD5yw7CtbgTpfjY8NfXWzwoxF1zOUEVsbww==
|
||||
dependencies:
|
||||
"@mapbox/node-pre-gyp" "^1.0.5"
|
||||
acorn "^8.1.0"
|
||||
acorn "^8.3.0"
|
||||
acorn-class-fields "^1.0.0"
|
||||
acorn-static-class-features "^1.0.0"
|
||||
bindings "^1.4.0"
|
||||
@@ -2283,10 +2283,10 @@ acorn@^7.1.1:
|
||||
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.2.0.tgz#17ea7e40d7c8640ff54a694c889c26f31704effe"
|
||||
integrity sha512-apwXVmYVpQ34m/i71vrApRrRKCWQnZZF1+npOD0WV5xZFfwWOmKGQ2RWlfdy9vWITsenisM8M0Qeq8agcFHNiQ==
|
||||
|
||||
acorn@^8.1.0:
|
||||
version "8.1.1"
|
||||
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.1.1.tgz#fb0026885b9ac9f48bac1e185e4af472971149ff"
|
||||
integrity sha512-xYiIVjNuqtKXMxlRMDc6mZUhXehod4a3gbZ1qRlM7icK4EbxUFNLhWoPblCvFtB2Y9CIqHP3CF/rdxLItaQv8g==
|
||||
acorn@^8.3.0:
|
||||
version "8.3.0"
|
||||
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.3.0.tgz#1193f9b96c4e8232f00b11a9edff81b2c8b98b88"
|
||||
integrity sha512-tqPKHZ5CaBJw0Xmy0ZZvLs1qTV+BNFSyvn77ASXkpBNfIRk8ev26fKrD9iLGwGA9zedPao52GSHzq8lyZG0NUw==
|
||||
|
||||
agent-base@4, agent-base@^4.1.0, agent-base@^4.3.0:
|
||||
version "4.3.0"
|
||||
@@ -8293,10 +8293,10 @@ onetime@^5.1.0:
|
||||
dependencies:
|
||||
mimic-fn "^2.1.0"
|
||||
|
||||
open@8.0.2:
|
||||
version "8.0.2"
|
||||
resolved "https://registry.yarnpkg.com/open/-/open-8.0.2.tgz#8c3e95cce93ba2fc8d99968ee8bfefecdb50b84f"
|
||||
integrity sha512-NV5QmWJrTaNBLHABJyrb+nd5dXI5zfea/suWawBhkHzAbVhLLiJdrqMgxMypGK9Eznp2Ltoh7SAVkQ3XAucX7Q==
|
||||
open@8.2.0:
|
||||
version "8.2.0"
|
||||
resolved "https://registry.yarnpkg.com/open/-/open-8.2.0.tgz#d6a4788b00009a9d60df471ecb89842a15fdcfc1"
|
||||
integrity sha512-O8uInONB4asyY3qUcEytpgwxQG3O0fJ/hlssoUHsBboOIRVZzT6Wq+Rwj5nffbeUhOdMjpXeISpDDzHCMRDuOQ==
|
||||
dependencies:
|
||||
define-lazy-prop "^2.0.0"
|
||||
is-docker "^2.1.1"
|
||||
|
||||
Reference in New Issue
Block a user