Skip to content

Commit

Permalink
ui: unbreak make watch
Browse files Browse the repository at this point in the history
By telling Webpack to proxy the path `/` through to the Cockroach process.
Webpack used to serve `/` itself from a static file, but as of cockroachdb#25195 we
generate `/` dynamically in Go, so we can use it to pass login state to
the UI.

Fixes cockroachdb#25858

Release note: None
  • Loading branch information
Pete Vilter committed May 23, 2018
1 parent aa02b29 commit 16c1df7
Show file tree
Hide file tree
Showing 3 changed files with 919 additions and 55 deletions.
2 changes: 1 addition & 1 deletion pkg/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"typescript": "^2.2.1",
"url-loader": "^0.5.8",
"webpack": "^3.5.6",
"webpack-dev-server": "^2.7.1"
"webpack-dev-server": "^2.11.2"
},
"engines": {
"node": ">=6",
Expand Down
31 changes: 26 additions & 5 deletions pkg/ui/webpack.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ try {
DashboardPlugin = class { apply() { /* no-op */ } };
}

const proxyPrefixes = ["/_admin", "/_status", "/ts", "/_auth"];
function shouldProxy(reqPath) {
if (reqPath === "/") {
return true;
}
return proxyPrefixes.some((prefix) => (
reqPath.startsWith(prefix)
));
}

// tslint:disable:object-literal-sort-keys
module.exports = (distDir, ...additionalRoots) => ({
entry: ["./src/index.tsx"],
Expand Down Expand Up @@ -116,10 +126,21 @@ module.exports = (distDir, ...additionalRoots) => ({

devServer: {
contentBase: path.join(__dirname, distDir),
proxy: [{
context: ["/_admin", "/_status", "/ts", "/_auth"],
secure: false,
target: process.env.TARGET,
}],
index: "",
proxy: {
// Note: this shouldn't require a custom bypass function to work;
// docs say that setting `index: ''` is sufficient to proxy `/`.
// However, that did not work, and may require upgrading to webpack 4.x.
"/": {
secure: false,
target: process.env.TARGET,
bypass: (req) => {
if (shouldProxy(req.path)) {
return false;
}
return req.path;
},
},
},
},
});
Loading

0 comments on commit 16c1df7

Please sign in to comment.