Skip to content

Instantly share code, notes, and snippets.

@kaluabentes
Created July 27, 2020 23:35
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 kaluabentes/01629ec7f8a07e04ddb06e6fde288f5c to your computer and use it in GitHub Desktop.
Save kaluabentes/01629ec7f8a07e04ddb06e6fde288f5c to your computer and use it in GitHub Desktop.
Stream file from source to response in Node.js
const http = require("http");
const fs = require("fs");
export default function Sitemap(req, res) {
const url = `${process.env.NEXT_PUBLIC_API_URL}/sitemap`;
const request = http.get(url, (response) => {
const contentType = response.headers["content-type"];
res.setHeader("Content-Type", contentType);
response.pipe(res);
});
request.on("error", function (e) {
console.error(e);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment