Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for websockets when proxy is enabled #637

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
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