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

Time:09-19

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.

CodePudding user response:

sendFile doesn't allow so many arguments

You wanted to use path.join

res.sendFile(path.join(__dirname, '../', 'frontend', 'build', 'index.html'))
  • Related