Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function request( url ) {
console.log(
'Requesting URL "%s"',
url.length > 70
? url.substring( 0, 67 ) + '...'
: url
);
const res = await phin.promisified( url );
if ( res.statusCode !== 200 ) {
throw new Error(
'HTTP response code ' + res.statusCode
+ ' for URL: ' + url
);
}
return res.body.toString();
}
function getVer () {
return rp({
url: versionUrl,
timeout: 15000
})
.then(res => res.body.toString())
}
res['route'] = async (opts) => {
if (!opts) throw new Error('Missing opts property.')
if (!opts.hasOwnProperty('origin') && !opts.hasOwnProperty('url')) throw new Error('Missing origin or url property for route options.')
let newHeaders = req.headers
if (newHeaders.hasOwnProperty('host')) newHeaders.host = url.parse(opts.origin).host
try {
let forwardRes = await p(Object.assign({
'method': req.method,
'headers': newHeaders,
'url': new url.URL(req.url.pathname, opts.origin).toString()
}, req.body ? {
'data': req.body
} : {}, opts, {
'stream': true
}))
res.writeHead(forwardRes.statusCode, forwardRes.headers)
forwardRes.stream.on('data', (chunk) => res.write(chunk))
forwardRes.stream.on('end', () => res.end())
}
catch (err) {
throw err
}
async function waitUntilServerStart (url) {
let serverStarted = false
while (!serverStarted) {
await rp({
url,
timeout: 100
})
.then(() => {
serverStarted = true
})
.catch(() => null)
}
}
function getReleaseInfo (filter) {
return rp({
url: releaseInfoUrl,
timeout: 15000
})
.then((res) => {
return JSON.parse(res.body.toString())
.release
.assets
.filter(filter)[0]
})
}