fix(content-server): Move serveStatic middleware after wildcard route

Because:
* The MIME type was a mismatch for JS and CSS files without the static directory being set before the wildcard settings route

This commit:
* Ensures the serveStatic middleware comes after the wildcard route in production
This commit is contained in:
Lauren Zugai 2023-01-05 19:17:22 -06:00
Родитель d8533565cf
Коммит 43c0f441c5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 0C86B71E24811D10
1 изменённых файлов: 23 добавлений и 19 удалений

Просмотреть файл

@ -189,19 +189,8 @@ function makeApp() {
const routeLogger = loggerFactory('server.routes');
const routeHelpers = routing(app, routeLogger);
if (config.get('env') === 'production') {
app.get(settingsPath, modifySettingsStatic);
addAllReactRoutesConditionally(app, routeHelpers, modifySettingsStatic);
}
if (config.get('env') === 'development') {
app.use(settingsPath, createSettingsProxy);
addAllReactRoutesConditionally(app, routeHelpers, createSettingsProxy);
} else {
app.get(settingsPath + '/*', modifySettingsStatic);
}
function addNonSettingsRoutes(middleware) {
addAllReactRoutesConditionally(app, routeHelpers, middleware);
/* This creates `app.whatever('/path' ...` handlers for every content-server route and
* excludes routes in `react-app.js` if corresponding feature flags are on. We manually add
@ -211,12 +200,27 @@ function makeApp() {
* route implementations. */
routes.forEach(routeHelpers.addRoute);
// must come after route handling
// must come after route handling but before wildcard routes
app.use(
serveStatic(STATIC_DIRECTORY, {
maxAge: config.get('static_max_age'),
})
);
}
if (config.get('env') === 'production') {
app.get(settingsPath, modifySettingsStatic);
addNonSettingsRoutes(modifySettingsStatic);
app.get(settingsPath + '/*', modifySettingsStatic);
}
if (config.get('env') === 'development') {
app.use(settingsPath, createSettingsProxy);
addNonSettingsRoutes(createSettingsProxy);
}
// it's a four-oh-four not found.
app.use(fourOhFour);