Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
npm-debug.log*
.dir-locals.el
.DS_Store
.idea/
16 changes: 11 additions & 5 deletions lib/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ function HttpServer(options) {
}));

if (typeof options.proxy === 'string') {
var proxy = httpProxy.createProxyServer({});
var proxy = httpProxy.createProxyServer({
target: options.proxy,
changeOrigin: true
});
before.push(function (req, res) {
proxy.web(req, res, {
target: options.proxy,
changeOrigin: true
}, function (err, req, res, target) {
proxy.web(req, res, {}, function (err, req, res, target) {
Comment on lines -166 to +171
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's different about creating the proxy with the options rather than using the options as before?

if (options.logFn) {
options.logFn(req, res, {
message: err.message,
Expand Down Expand Up @@ -199,6 +199,12 @@ function HttpServer(options) {
if (options.timeout !== undefined) {
this.server.setTimeout(options.timeout);
}

if (typeof options.proxy === 'string') {
this.server.on('upgrade', function (request, socket, head) {
proxy.ws(request, socket, head);
});
}
}

HttpServer.prototype.listen = function () {
Expand Down