-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Encapsulate sockjs, introduce ws and build base for users to make own server implementation #1904
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5a6b2a4
refactor(server): encapsulated sockjs
knagaitsev 2f22843
refactor(server): added some comments, removed commented out code
knagaitsev 62cc34c
refactor(server): moved server implementations, fix naming
knagaitsev f915ce5
refactor(server): rename files, pass in full server object
knagaitsev 8f6bd69
refactor(server): fixed capitalization
knagaitsev 11b6522
refactor(server): renamed ws server
knagaitsev bee6f83
Merge branch 'master' into clientMode
evilebottnawi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
// base class that users should extend if they are making their own | ||
// server implementation | ||
module.exports = class BaseServer { | ||
constructor(server) { | ||
this.server = server; | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable | ||
class-methods-use-this, | ||
func-names | ||
*/ | ||
const sockjs = require('sockjs'); | ||
const BaseServer = require('./BaseServer'); | ||
|
||
// Workaround for sockjs@~0.3.19 | ||
// sockjs will remove Origin header, however Origin header is required for checking host. | ||
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information | ||
{ | ||
// eslint-disable-next-line global-require | ||
const SockjsSession = require('sockjs/lib/transport').Session; | ||
const decorateConnection = SockjsSession.prototype.decorateConnection; | ||
SockjsSession.prototype.decorateConnection = function(req) { | ||
decorateConnection.call(this, req); | ||
const connection = this.connection; | ||
if ( | ||
connection.headers && | ||
!('origin' in connection.headers) && | ||
'origin' in req.headers | ||
) { | ||
connection.headers.origin = req.headers.origin; | ||
} | ||
}; | ||
} | ||
|
||
module.exports = class SockJSServer extends BaseServer { | ||
// options has: error (function), debug (function), server (http/s server), path (string) | ||
constructor(server) { | ||
super(server); | ||
this.socket = sockjs.createServer({ | ||
// Use provided up-to-date sockjs-client | ||
sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js', | ||
// Limit useless logs | ||
log: (severity, line) => { | ||
if (severity === 'error') { | ||
this.server.log.error(line); | ||
} else { | ||
this.server.log.debug(line); | ||
} | ||
}, | ||
}); | ||
|
||
this.socket.installHandlers(this.server.listeningApp, { | ||
prefix: this.server.sockPath, | ||
}); | ||
} | ||
|
||
send(connection, message) { | ||
connection.write(message); | ||
} | ||
|
||
close(connection) { | ||
connection.close(); | ||
} | ||
|
||
// f should return the resulting connection | ||
onConnection(f) { | ||
this.socket.on('connection', f); | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
// const ws = require('ws'); | ||
const BaseServer = require('./BaseServer'); | ||
|
||
// ws server implementation under construction | ||
// will need changes in the client as well to function | ||
module.exports = class WebsocketServer extends BaseServer {}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
// base class that users should extend if they are making their own | ||
// server implementation | ||
module.exports = class BaseServer { | ||
constructor(server) { | ||
this.server = server; | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file name should be changed from |
||
|
||
/* eslint-disable | ||
class-methods-use-this, | ||
func-names | ||
*/ | ||
const sockjs = require('sockjs'); | ||
const BaseServer = require('./BaseServer'); | ||
|
||
// Workaround for sockjs@~0.3.19 | ||
// sockjs will remove Origin header, however Origin header is required for checking host. | ||
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information | ||
{ | ||
// eslint-disable-next-line global-require | ||
const SockjsSession = require('sockjs/lib/transport').Session; | ||
const decorateConnection = SockjsSession.prototype.decorateConnection; | ||
SockjsSession.prototype.decorateConnection = function(req) { | ||
decorateConnection.call(this, req); | ||
const connection = this.connection; | ||
if ( | ||
connection.headers && | ||
!('origin' in connection.headers) && | ||
'origin' in req.headers | ||
) { | ||
connection.headers.origin = req.headers.origin; | ||
} | ||
}; | ||
} | ||
|
||
module.exports = class SockJSServer extends BaseServer { | ||
// options has: error (function), debug (function), server (http/s server), path (string) | ||
constructor(server) { | ||
super(server); | ||
this.socket = sockjs.createServer({ | ||
// Use provided up-to-date sockjs-client | ||
sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js', | ||
// Limit useless logs | ||
log: (severity, line) => { | ||
if (severity === 'error') { | ||
this.server.log.error(line); | ||
} else { | ||
this.server.log.debug(line); | ||
} | ||
}, | ||
}); | ||
|
||
this.socket.installHandlers(this.server.listeningApp, { | ||
prefix: this.server.sockPath, | ||
}); | ||
} | ||
|
||
send(connection, message) { | ||
connection.write(message); | ||
} | ||
|
||
close(connection) { | ||
connection.close(); | ||
} | ||
|
||
// f should return the resulting connection | ||
onConnection(f) { | ||
this.socket.on('connection', f); | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file name should be changed from
baseServer.js
toBaseServer
.