Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Express JS direct redirecting index page results in blank page

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!