Skip to content

Commit bd976f2

Browse files
VoluneSpaceK33z
authored andcommitted
Serve sockjs.js from sockjs-client dependency, don't use default from CDN (#493)
1 parent 155d036 commit bd976f2

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
/client/live.bundle.js
33
/client/index.bundle.js
4+
/client/sockjs.bundle.js

client/sockjs.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('sockjs-client');

client/webpack.sockjs.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
output: {
3+
library: "SockJS",
4+
libraryTarget: "umd"
5+
}
6+
}

lib/Server.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ var https = require("https");
1010
var httpProxyMiddleware = require("http-proxy-middleware");
1111
var serveIndex = require("serve-index");
1212
var historyApiFallback = require("connect-history-api-fallback");
13-
var pkg = require("../package.json");
1413

1514
function Server(compiler, options) {
1615
// Default options
@@ -48,6 +47,10 @@ function Server(compiler, options) {
4847
var inlinedJs = new StreamCache();
4948
fs.createReadStream(path.join(__dirname, "..", "client", "index.bundle.js")).pipe(inlinedJs);
5049

50+
// Prepare the sockjs js file
51+
var sockjsJs = new StreamCache();
52+
fs.createReadStream(path.join(__dirname, "..", "client", "sockjs.bundle.js")).pipe(sockjsJs);
53+
5154
// Init express server
5255
var app = this.app = new express();
5356

@@ -59,6 +62,11 @@ function Server(compiler, options) {
5962
liveJs.pipe(res);
6063
});
6164

65+
app.get("/__webpack_dev_server__/sockjs.bundle.js", function(req, res) {
66+
res.setHeader("Content-Type", "application/javascript");
67+
sockjsJs.pipe(res);
68+
});
69+
6270
app.get("/webpack-dev-server.js", function(req, res) {
6371
res.setHeader("Content-Type", "application/javascript");
6472
inlinedJs.pipe(res);
@@ -335,9 +343,8 @@ Server.prototype.setContentHeaders = function(req, res, next) {
335343
Server.prototype.listen = function() {
336344
var returnValue = this.listeningApp.listen.apply(this.listeningApp, arguments);
337345
var sockServer = sockjs.createServer({
338-
// The SockJS server package uses a version of the client script
339-
// that doesn't match our version of the client script.
340-
sockjs_url: 'https://cdn.jsdelivr.net/sockjs/' + pkg.dependencies['sockjs-client'] + '/sockjs.min.js',
346+
// Use provided up-to-date sockjs-client
347+
sockjs_url: "/__webpack_dev_server__/sockjs.bundle.js",
341348
// Limit useless logs
342349
log: function(severity, line) {
343350
if(severity === "error") {

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@
4949
"ssl/"
5050
],
5151
"scripts": {
52-
"prepublish": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js -p && webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js -p",
53-
"lint": "eslint bin lib test examples client/{index,live,socket,webpack.config}.js",
52+
"prepublish": "npm run -s client-live && npm run -s client-index && npm run -s client-sockjs",
53+
"client-live": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js -p",
54+
"client-index": "webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js -p",
55+
"client-sockjs": "webpack ./client/sockjs.js client/sockjs.bundle.js --color --config client/webpack.sockjs.config.js -p",
56+
"lint": "eslint bin lib test examples client/{index,live,socket,sockjs,webpack.config}.js",
5457
"beautify": "npm run lint -- --fix",
5558
"travis": "npm run lint && node lib/Server.js"
5659
}

0 commit comments

Comments
 (0)