Skip to content

Instantly share code, notes, and snippets.

@lukeshumard
lukeshumard / helper.js
Created October 2, 2019 10:05
Getting @now/node helpers with tests
const micro = require('micro');
// taken directly from
// https://github.com/zeit/now-builders/blob/f67480a98ac461dc2fe6bb27e8a4ea86e9b6b60a/packages/now-node/src/helpers.ts#L47-L60
function queryParser({ url = '/' }) {
const { URL } = require('url');
// we provide a placeholder base url because we only want searchParams
const params = new URL(url, 'https://n').searchParams;
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
} else {
var error = new Error(response.statusText);
error.response = response;
throw error;
}
};