Compare commits

..

4 Commits

Author SHA1 Message Date
Andy Bitz
7945155a0f Publish Canary
- vercel@20.0.0-canary.24
 - @vercel/next@2.6.23-canary.0
 - @vercel/node@1.7.5-canary.2
 - @vercel/routing-utils@1.8.4-canary.5
2020-08-19 15:01:35 +02:00
Andy
edb6043c2c [cli] Always show renewal price for domains inspect (#5060)
* [cli] Always show renwal price for `domains inspect`

* Update test
2020-08-19 15:00:33 +02:00
Markoz Peña
971481ba51 [node] Add res.redirect() helper method (#4947)
This pull request adds a method redirect, the behavior will be the same as that of Next.js with `pages/api`. This PR takes into account the change that is being made in Next.js with redirect due to the [error that was reported](https://github.com/vercel/next.js/issues/15594) a few hours ago.

Co-authored-by: Steven <steven@ceriously.com>
2020-08-18 18:58:54 -04:00
JJ Kasper
db8e456603 Publish canary
- @vercel/routing-utils@1.8.4-canary.4
2020-08-18 12:37:22 -05:00
9 changed files with 86 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "vercel",
"version": "20.0.0-canary.23",
"version": "20.0.0-canary.24",
"preferGlobal": true,
"license": "Apache-2.0",
"description": "The command-line interface for Vercel",
@@ -63,7 +63,7 @@
"dependencies": {
"@vercel/build-utils": "2.4.3-canary.4",
"@vercel/go": "1.1.5-canary.0",
"@vercel/node": "1.7.5-canary.1",
"@vercel/node": "1.7.5-canary.2",
"@vercel/python": "1.2.2",
"@vercel/ruby": "1.2.3",
"update-notifier": "4.1.0"

View File

@@ -111,12 +111,11 @@ export default async function inspect(
` ${chalk.cyan('Created At')}\t\t\t${formatDate(domain.createdAt)}\n`
);
output.print(` ${chalk.cyan('Edge Network')}\t\tyes\n`);
if (renewalPrice && domain.boughtAt) {
output.print(
` ${chalk.cyan('Renewal Price')}\t\t$${renewalPrice} USD\n`
);
}
output.print(
` ${chalk.cyan('Renewal Price')}\t\t${
domain.boughtAt && renewalPrice ? `$${renewalPrice} USD` : chalk.gray('-')
}\n`
);
output.print('\n');

View File

@@ -1052,7 +1052,7 @@ test('domains inspect', async t => {
}
);
t.true(!stderr.includes(`Renewal Price`));
t.true(stderr.includes(`Renewal Price`));
t.is(exitCode, 0, formatOutput({ stdout, stderr }));
{

View File

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

View File

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

View File

@@ -73,6 +73,24 @@ function status(res: NowResponse, statusCode: number): NowResponse {
return res;
}
function redirect(
res: NowResponse,
statusOrUrl: string | number,
url?: string
): NowResponse {
if (typeof statusOrUrl === 'string') {
url = statusOrUrl;
statusOrUrl = 307;
}
if (typeof statusOrUrl !== 'number' || typeof url !== 'string') {
throw new Error(
`Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').`
);
}
res.writeHead(statusOrUrl, { Location: url }).end();
return res;
}
function setCharset(type: string, charset: string) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { parse, format } = require('content-type');
@@ -261,6 +279,7 @@ export function createServerWithHelpers(
setLazyProp<NowRequestBody>(req, 'body', getBodyParser(req, event.body));
res.status = statusCode => status(res, statusCode);
res.redirect = (statusOrUrl, url) => redirect(res, statusOrUrl, url);
res.send = body => send(req, res, body);
res.json = jsonBody => json(req, res, jsonBody);

View File

@@ -14,9 +14,7 @@ export type NowResponse = ServerResponse & {
send: (body: any) => NowResponse;
json: (jsonBody: any) => NowResponse;
status: (statusCode: number) => NowResponse;
redirect: (statusOrUrl: string | number, url?: string) => NowResponse;
};
export type NowApiHandler = (
req: NowRequest,
res: NowResponse
) => void;
export type NowApiHandler = (req: NowRequest, res: NowResponse) => void;

View File

@@ -65,6 +65,7 @@ describe('all helpers', () => {
['cookies', 0],
['body', 0],
['status', 1],
['redirect', 1],
['send', 1],
['json', 1],
];
@@ -307,6 +308,59 @@ describe('res.status', () => {
});
});
describe('res.redirect', () => {
test('should redirect to login', async () => {
mockListener.mockImplementation((req, res) => {
res.redirect('/login');
res.end();
});
const res = await fetchWithProxyReq(url, { redirect: 'manual' });
expect(res.status).toBe(307);
expect(res.headers.get('location')).toBe(url + '/login');
});
test('should redirect with status code 301', async () => {
mockListener.mockImplementation((req, res) => {
res.redirect(301, '/login');
res.end();
});
const res = await fetchWithProxyReq(url, { redirect: 'manual' });
expect(res.status).toBe(301);
expect(res.headers.get('location')).toBe(url + '/login');
});
test('should show friendly error for invalid redirect', async () => {
let error;
mockListener.mockImplementation((req, res) => {
try {
res.redirect(307);
} catch (err) {
error = err;
}
res.end();
});
await fetchWithProxyReq(url, { redirect: 'manual' });
expect(error.message).toBe(
`Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').`
);
});
test('should show friendly error in case of passing null as first argument redirect', async () => {
let error;
mockListener.mockImplementation((req, res) => {
try {
res.redirect(null);
} catch (err) {
error = err;
}
res.end();
});
await fetchWithProxyReq(url, { redirect: 'manual' });
expect(error.message).toBe(
`Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').`
);
});
});
// tests based on expressjs test suite
// see https://github.com/expressjs/express/blob/master/test/res.send.js
describe('res.send', () => {

View File

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