I can't figure out how to set a Cache-Control header for static assets using express.js and webpack.
In my react app I'm including static images as follows:
<img src={require("./images/Logo.png")} alt="Logo"/>
I have a loader in my webpack.config.js that outputs images to /public/images
module: {
loaders: [
{
test: /\.png/,
loader: 'url-loader?limit=10000&name=public/images/[name].[ext]'
}]
}
Finally, I mark the /public folder in server.js as containing static assets and set the Cache-Control header
const server = express();
server.use(express.static(path.join(__dirname, 'public'), {maxAge: "30d"}));
The problem is that require() resolves the path including /public folder:
<img class="full-width" src="/public/images/Logo.png" alt="Logo">
but express expects a URL without the public/ part.
Is there a way to force express.static() to include the /public in its path?