Created
July 27, 2020 23:35
-
-
Save kaluabentes/01629ec7f8a07e04ddb06e6fde288f5c to your computer and use it in GitHub Desktop.
Stream file from source to response in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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