I implemented a simple middleware "checkMaintenanceMode", which redirects each page to a static maintenance / under construction page.
const initStaticPages = (router) => {
router.use('/main', checkMaintenanceMode, requireAccess, express.static('public'))
router.use('/logout?reason=timeout', checkMaintenanceMode, express.static('public'))
router.use('/logout', checkMaintenanceMode, express.static('public'))
router.use('/login', checkMaintenanceMode, express.static('public'))
router.use('/requestHistory', checkMaintenanceMode, requireAccess, express.static('public'))
router.use('/recurringRequest', checkMaintenanceMode, requireAccess, express.static('public'))
router.use('/maintenance', express.static('public'))
router.use('/', checkMaintenanceMode, express.static('public'))
const checkMaintenanceMode = (req, res, next) => {
if (maintenanceMode) {
res.redirect('/maintenance/')
} else {
next()
}
}
When adding the middleware to the "/" route, loading the index page results in a blank page with error message: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
Any idea what could be the reason for that?
When using router.use('/', express.static('public')), it works, but I also want to redirect directly when a user opens the page.