cors-expo-jey
Advanced tools
Comparing version 0.4.5 to 0.4.6
@@ -11,3 +11,3 @@ // © 2013 - 2016 Rob Wu <rob@robwu.nl> | ||
var getProxyForUrl = require('proxy-from-env').getProxyForUrl; | ||
var zlib = require('zlib'); | ||
const zlib = require('zlib'); | ||
@@ -222,44 +222,32 @@ var help_text = {}; | ||
/// | ||
/// | ||
/// | ||
/// | ||
/// | ||
/// | ||
/// | ||
/// | ||
/// | ||
let data = []; | ||
// Check if the response is compressed | ||
const encoding = proxyRes.headers['content-encoding']; | ||
// Check if the response is compressed | ||
const encoding = proxyRes.headers['content-encoding']; | ||
let stream = proxyRes; | ||
if (encoding === 'gzip') { | ||
stream = proxyRes.pipe(zlib.createGunzip()); | ||
} else if (encoding === 'deflate') { | ||
stream = proxyRes.pipe(zlib.createInflate()); | ||
} | ||
let stream = proxyRes; | ||
if (encoding === 'gzip') { | ||
stream = proxyRes.pipe(zlib.createGunzip()); | ||
} else if (encoding === 'deflate') { | ||
stream = proxyRes.pipe(zlib.createInflate()); | ||
} | ||
// Collect chunks of data | ||
stream.on('data', (chunk) => { | ||
data.push(chunk); | ||
}); | ||
// Collect chunks of data | ||
stream.on('data', (chunk) => { | ||
data.push(chunk); | ||
}); | ||
// Concatenate and convert to string when the stream ends | ||
stream.on('end', () => { | ||
const text = Buffer.concat(data).toString('utf8'); | ||
console.log('Decompressed response:', text); | ||
}); | ||
// Concatenate and convert to string when the stream ends | ||
stream.on('end', () => { | ||
const text = Buffer.concat(data).toString('utf8'); | ||
console.log('Decompressed response:', text); | ||
}); | ||
stream.on('error', (err) => { | ||
console.error('Error handling response:', err); | ||
}); | ||
stream.on('error', (err) => { | ||
console.error('Error handling response:', err); | ||
}); | ||
proxyRes.headers['x-final-url'] = requestState.location.href; | ||
@@ -347,7 +335,7 @@ withCORS(proxyRes.headers, req); | ||
// TODO: HACK: Add api.expo.dev to the URL | ||
req.url = 'api.expo.dev' + req.url; | ||
req.url = '/https://api.expo.dev' + req.url; | ||
req.headers.origin = 'https://api.expo.dev'; | ||
req.headers.origin = 'https://localhost:8081'; | ||
req.headers['x-requested-with'] = 'XMLHttpRequest'; | ||
console.log(req.url); | ||
console.log('== changed req.url: ',req.url); | ||
req.corsAnywhereRequestState = { | ||
@@ -354,0 +342,0 @@ getProxyForUrl: corsAnywhere.getProxyForUrl, |
{ | ||
"name": "cors-expo-jey", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"description": "CORS Anywhere is a reverse proxy which adds CORS headers to the proxied request. Request URL is taken from the path", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -1,2 +0,6 @@ | ||
var cors_proxy = require('cors-expo-jey'); | ||
var cors_proxy = require('./lib/cors-anywhere'); | ||
var host = '0.0.0.0'; | ||
var port = 3000; | ||
cors_proxy.createServer({ | ||
@@ -18,4 +22,4 @@ requireHeader: ['origin', 'x-requested-with'], | ||
}, | ||
}).listen(3000, '0.0.0.0', function() { | ||
console.log('Running CORS Anywhere on 0.0.0.0:3000'); | ||
}).listen(port, host, function() { | ||
console.log('Running CORS Anywhere on ' + host + ':' + port); | ||
}); |
117584
2336