Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paurakhsharma/b2ff8dec24a849b6b8770dd6cef14486 to your computer and use it in GitHub Desktop.
Save paurakhsharma/b2ff8dec24a849b6b8770dd6cef14486 to your computer and use it in GitHub Desktop.
Firebase cloud functions image proxy server. I use it to overcome Flutter CORS issues with the images. ie. CORS Proxy server
const cors = require('cors')({ origin: true });
const request = require('request');
functions.https.onRequest((req, res) {
cors(req, res, () => {
let url = req.query.url;
if (!url) {
url = req.body.url;
}
if (!url) {
res.status(403).send('URL is empty.');
}
return request.get(url).pipe(res);
});
})
@paurakhsharma
Copy link
Author

Make sure you have installed cors and request package.
e.g

npm install cors request --save

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment