Skip to content

Commit 8f6bd69

Browse files
committed
refactor(server): fixed capitalization
1 parent f915ce5 commit 8f6bd69

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

lib/servers/BaseServer.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
// base class that users should extend if they are making their own
4+
// server implementation
5+
module.exports = class BaseServer {
6+
constructor(server) {
7+
this.server = server;
8+
}
9+
};

lib/servers/SockJSServer.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
'use strict';
2+
3+
/* eslint-disable
4+
class-methods-use-this,
5+
func-names
6+
*/
7+
const sockjs = require('sockjs');
8+
const BaseServer = require('./BaseServer');
9+
10+
// Workaround for sockjs@~0.3.19
11+
// sockjs will remove Origin header, however Origin header is required for checking host.
12+
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
13+
{
14+
// eslint-disable-next-line global-require
15+
const SockjsSession = require('sockjs/lib/transport').Session;
16+
const decorateConnection = SockjsSession.prototype.decorateConnection;
17+
SockjsSession.prototype.decorateConnection = function(req) {
18+
decorateConnection.call(this, req);
19+
const connection = this.connection;
20+
if (
21+
connection.headers &&
22+
!('origin' in connection.headers) &&
23+
'origin' in req.headers
24+
) {
25+
connection.headers.origin = req.headers.origin;
26+
}
27+
};
28+
}
29+
30+
module.exports = class SockJSServer extends BaseServer {
31+
// options has: error (function), debug (function), server (http/s server), path (string)
32+
constructor(server) {
33+
super(server);
34+
this.socket = sockjs.createServer({
35+
// Use provided up-to-date sockjs-client
36+
sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js',
37+
// Limit useless logs
38+
log: (severity, line) => {
39+
if (severity === 'error') {
40+
this.server.log.error(line);
41+
} else {
42+
this.server.log.debug(line);
43+
}
44+
},
45+
});
46+
47+
this.socket.installHandlers(this.server.listeningApp, {
48+
prefix: this.server.sockPath,
49+
});
50+
}
51+
52+
send(connection, message) {
53+
connection.write(message);
54+
}
55+
56+
close(connection) {
57+
connection.close();
58+
}
59+
60+
// f should return the resulting connection
61+
onConnection(f) {
62+
this.socket.on('connection', f);
63+
}
64+
};

lib/servers/WsServer.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
// const ws = require('ws');
4+
const BaseServer = require('./BaseServer');
5+
6+
// ws server implementation under construction
7+
// will need changes in the client as well to function
8+
module.exports = class WsServer extends BaseServer {};

0 commit comments

Comments
 (0)