Skip to content

Serve sockjs.js from sockjs-client dependency, don't use default from CDN #493

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

Merged
merged 1 commit into from
Sep 16, 2016
Merged
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
@@ -1,3 +1,4 @@
node_modules
/client/live.bundle.js
/client/index.bundle.js
/client/sockjs.bundle.js
1 change: 1 addition & 0 deletions client/sockjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('sockjs-client');
6 changes: 6 additions & 0 deletions client/webpack.sockjs.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
output: {
library: "SockJS",
libraryTarget: "umd"
}
}
15 changes: 11 additions & 4 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var https = require("https");
var httpProxyMiddleware = require("http-proxy-middleware");
var serveIndex = require("serve-index");
var historyApiFallback = require("connect-history-api-fallback");
var pkg = require("../package.json");

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

// Prepare the sockjs js file
var sockjsJs = new StreamCache();
fs.createReadStream(path.join(__dirname, "..", "client", "sockjs.bundle.js")).pipe(sockjsJs);

// Init express server
var app = this.app = new express();

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

app.get("/__webpack_dev_server__/sockjs.bundle.js", function(req, res) {
res.setHeader("Content-Type", "application/javascript");
sockjsJs.pipe(res);
});

app.get("/webpack-dev-server.js", function(req, res) {
res.setHeader("Content-Type", "application/javascript");
inlinedJs.pipe(res);
Expand Down Expand Up @@ -308,9 +316,8 @@ Server.prototype.setContentHeaders = function(req, res, next) {
Server.prototype.listen = function() {
var returnValue = this.listeningApp.listen.apply(this.listeningApp, arguments);
var sockServer = sockjs.createServer({
// The SockJS server package uses a version of the client script
// that doesn't match our version of the client script.
sockjs_url: 'https://cdn.jsdelivr.net/sockjs/' + pkg.dependencies['sockjs-client'] + '/sockjs.min.js',
// Use provided up-to-date sockjs-client
sockjs_url: "/__webpack_dev_server__/sockjs.bundle.js",
// Limit useless logs
log: function(severity, line) {
if(severity === "error") {
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@
"ssl/"
],
"scripts": {
"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",
"lint": "eslint bin lib test examples client/{index,live,socket,webpack.config}.js",
"prepublish": "npm run -s client-live && npm run -s client-index && npm run -s client-sockjs",
"client-live": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js -p",
"client-index": "webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js -p",
"client-sockjs": "webpack ./client/sockjs.js client/sockjs.bundle.js --color --config client/webpack.sockjs.config.js -p",
"lint": "eslint bin lib test examples client/{index,live,socket,sockjs,webpack.config}.js",
"beautify": "npm run lint -- --fix",
"travis": "npm run lint && node lib/Server.js"
}
Expand Down