Skip to content

Instantly share code, notes, and snippets.

@adityatelange
Created June 29, 2022 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityatelange/c6da27ed98800546d6ec0cecbce2ea34 to your computer and use it in GitHub Desktop.
Save adityatelange/c6da27ed98800546d6ec0cecbce2ea34 to your computer and use it in GitHub Desktop.
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
// The main, exported, function of the endpoint,
// dealing with the request and subsequent response
module.exports = async (req, res) => {
const url = req.query.url || req.body.url;
const res = await fetch(url, {
method: 'GET',
});
// Store fetched HTML in data
const data = await res.text();
res.status(200).send(data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment