Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect all server requests to index.html file in node.js

I have found the solution to error from here

app.get('/*', function(req, res) {
  res.sendFile(path.join(__dirname, 'path/to/your/index.html'), function(err) {
    if (err) {
      res.status(500).send(err)
    }
  })
})

but I am not able to understand what I have actually write in that index.html file

enter image description here

like image 407
Aryan Avatar asked Oct 19 '25 05:10

Aryan


1 Answers

This solved my problem all thanks to @Mosh Feu Who helped me a lot in this problem solving you can see discussion in this chat

NOTE : use index.html file after declaring routes to api

app.use("/api", indexRouter);

app.get('/*', function (req, res) {
  res.sendFile(path.join(__dirname, '/build/index.html'), function (err) {
    if (err) {
      res.status(500).send(err)
    }
  })
})
like image 124
Aryan Avatar answered Oct 21 '25 20:10

Aryan