Skip to content

Commit c5fdbbf

Browse files
author
Shane Osbourne
committed
fix(client-script): allow proxy to also use client script middleware
1 parent dbe9ffe commit c5fdbbf

File tree

3 files changed

+6
-31
lines changed

3 files changed

+6
-31
lines changed

lib/async.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module.exports = {
170170
bs.pluginManager.get("client:script")(
171171
bs.options.toJS(),
172172
clientJs,
173-
bs.options.get("proxy") ? "file" : "middleware"
173+
"middleware"
174174
)
175175
);
176176

lib/server/proxy-server.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use strict";
22

3-
var snippetUtils = require("./../snippet").utils;
43
var _ = require("lodash");
54
var utils = require("./utils");
65
var Immutable = require("immutable");
@@ -26,6 +25,9 @@ module.exports = function createProxyServer (bs, scripts) {
2625

2726
var proxy = utils.getServer(bs.proxy.app, bs.options);
2827

28+
bs.proxy.app.use(bs.options.getIn(["scriptPaths", "versioned"]), scripts);
29+
bs.proxy.app.use(bs.options.getIn(["scriptPaths", "path"]), scripts);
30+
2931
/**
3032
* How best to handle websockets going forward?
3133
*/
@@ -36,9 +38,8 @@ module.exports = function createProxyServer (bs, scripts) {
3638

3739
/**
3840
* @param bs
39-
* @param scripts
4041
*/
41-
function getOptions (bs, scripts) {
42+
function getOptions (bs) {
4243

4344
var options = bs.options;
4445

@@ -50,7 +51,7 @@ function getOptions (bs, scripts) {
5051
rules: rules.opts.rules,
5152
whitelist: rules.opts.whitelist,
5253
blacklist: rules.opts.blacklist,
53-
middleware: options.get("middleware").toJS().concat(getPluginMiddleware(bs, scripts)),
54+
middleware: options.get("middleware").toJS().concat(bs.pluginManager.hook("server:middleware")),
5455
errHandler: function (err) {
5556
bs.logger.debug("{red:[proxy error]} %s", err.message);
5657
}
@@ -73,18 +74,6 @@ function getOptions (bs, scripts) {
7374
return out;
7475
}
7576

76-
/**
77-
* Get proxy specific middleware
78-
* @param bs
79-
* @param scripts
80-
* @returns {*}
81-
*/
82-
function getPluginMiddleware (bs, scripts) {
83-
return bs.pluginManager.hook("server:middleware", [
84-
snippetUtils.getProxyMiddleware(scripts, bs.options.getIn(["scriptPaths", "versioned"]))
85-
]);
86-
}
87-
8877
/**
8978
* @param {Object} opts
9079
* @param {Function} cb

lib/snippet.js

-14
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,6 @@ var utils = {
6464
whitelist: options.get("whitelist").toJS()
6565
};
6666
},
67-
/**
68-
* @param {String} scripts - the client side JS
69-
* @param {String} scriptPath - the URL to match
70-
* @returns {Function}
71-
*/
72-
getProxyMiddleware: function (scripts, scriptPath) {
73-
return function serveBsJavascriptfile (req, res, next) {
74-
if (req.url.indexOf(scriptPath) > -1) {
75-
res.writeHead(200, {"Content-Type": "text/javascript"});
76-
return res.end(scripts);
77-
}
78-
next();
79-
};
80-
},
8167
/**
8268
* @param {Object} req
8369
* @param {Array} [excludeList]

0 commit comments

Comments
 (0)