【发布时间】:2018-11-10 10:39:45
【问题描述】:
我尝试创建一个 http 服务器,它将在 https://google.com 下载 HTML
并提供它(在 localhost:3000)。一种代理。
使用此代码:
const express = require('express')
const https = require('https')
const app = express()
app.get('/', function (req, mainRes) {
https.get('https://www.google.fr', (res) => {
res.on('data', (d) => {
mainRes.send(d)
})
})
})
app.listen(3000)
google.com 的 html 似乎已下载,但服务器因此错误而崩溃:
Error: Can't set headers after they are sent.
我知道这与 2 个打包的请求有关,但我不知道如何解决。
【问题讨论】:
标签: node.js express https http-proxy