Commit 84b91734 authored by Benjamin Bouvier's avatar Benjamin Bouvier
Browse files

Use a relative empty path for assets (fixes #1107).

parent 55d2bc4f
Pipeline #408436 passed with stage
in 4 minutes and 5 seconds
......@@ -18,7 +18,18 @@ async function start() {
// Middleware for removing the url prefix, if it's set.
if (process.kresus.urlPrefix !== '/') {
const rootRegexp = makeUrlPrefixRegExp(process.kresus.urlPrefix);
app.use((req, _res, next) => {
// We use a trick here, by having something that rewrites the URL by
// removing the URL prefix if it was set.
//
// This means that if the browser tries to access any resource without
// the URL prefix, this would work; so make sure to return 404 on these
// accesses, to avoid hard-to-debug situations.
app.use((req, res, next) => {
// Safeguard against misuses.
if (!req.url.startsWith(process.kresus.urlPrefix)) {
res.status(404);
return false;
}
req.url = req.url.replace(rootRegexp, '/');
return next();
});
......
......@@ -55,7 +55,10 @@ const config = {
output: {
path: path.resolve(__dirname, 'build', 'client'),
filename: '[name].js',
publicPath: process.env.ASSET_PATH || '/'
// ASSET_PATH is provided by webpack-dev-server; when it's not set, use
// an empty path so it works with relative paths and thus with an URL
// prefix.
publicPath: process.env.ASSET_PATH || ''
},
module: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment