informer informer - 26 days ago 7
React JSX Question

Glyphicons and fonts not working with Express server and create-react-app build

I am getting error in the browser console:
Failed to decode downloaded font "localhost:5000/static/media/fontname.@#$.woff"
OTS parsing error: invalid version tag

Found few solutions/hacks like adding a homepage:"./" to package.json. But none of them worked.
Any real fix for this ?

Answer Source

Found the fix. All the fonts and images go to the /static/media inside the build folder. Express needs a proper mapping of these folders to access files in the same.

`app.use('/static/media', express.static(path.join(__dirname, '/client/build/static/media/'), {maxAge: 3600000}));