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,35 +189,39 @@ function makeApp() {
const routeLogger = loggerFactory('server.routes');
const routeHelpers = routing(app, routeLogger);
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
* these excluded routes for content-server to serve in checks above if the feature flag is
* set to false or if the request does not contain `showReactApp=true`. Adding these routes
* must come after React-related route modifications so that `next('route')` skips to these
* route implementations. */
routes.forEach(routeHelpers.addRoute);
// 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);
addAllReactRoutesConditionally(app, routeHelpers, modifySettingsStatic);
addNonSettingsRoutes(modifySettingsStatic);
app.get(settingsPath + '/*', modifySettingsStatic);
}
if (config.get('env') === 'development') {
app.use(settingsPath, createSettingsProxy);
addAllReactRoutesConditionally(app, routeHelpers, createSettingsProxy);
} else {
app.get(settingsPath + '/*', modifySettingsStatic);
addNonSettingsRoutes(createSettingsProxy);
}
/* 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
* these excluded routes for content-server to serve in checks above if the feature flag is
* set to false or if the request does not contain `showReactApp=true`. Adding these routes
* must come after React-related route modifications so that `next('route')` skips to these
* route implementations. */
routes.forEach(routeHelpers.addRoute);
// must come after route handling
app.use(
serveStatic(STATIC_DIRECTORY, {
maxAge: config.get('static_max_age'),
})
);
// it's a four-oh-four not found.
app.use(fourOhFour);