Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't feed React index.html file to NodeJS server

I’m trying to feed the index.html file from my frontend build folder and I get a strange error:
send deprecated hidden: use dotfiles: ‘allow’ instead

Here is the code I’m running:

    if (process.env.NODE_ENV === 'production') {
  app.use(
    express.static(path.join(__dirname, '../frontend/build'), {
      dotfiles: 'allow',
    })
  )

  app.get('*', (req, res) => {
    res.sendFile(__dirname, '../', 'frontend', 'build', 'index.html')
  })
} else {
  app.get('/', (req, res) => {
    res.status(200).json({ message: 'Welcome to the API' })
  })
}

Although I have set dotfiles: ‘allow’ , the error doesn’t go away. The error appears when I acces the frontend app’s main page in the browser. The main page opens, but the server crashes after that.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

sendFile doesn’t allow so many arguments

You wanted to use path.join

res.sendFile(path.join(__dirname, '../', 'frontend', 'build', 'index.html'))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading