I've been trying to get this fixed for the last few hours but can't find something that works. What I'm using right now is the standard:
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
I've tried to use the solution someone posted in another thread:
app.get(/*./, function (req, res) {
res.sendFile(__dirname + '/index.html');
});
But this doesn't work and gives me a "Uncaught SyntaxError: Unexpected token <".
I guess that solution is based of expressjs own examples:
app.get(/*test$./, function (req, res) {
res.sendFile(__dirname + '/index.html');
});
Which works for every route that has the phrase "test" in the first level (and ONLY the first lvl '/test'=yes, '/app/test'=no.
WHAT I WANT: Since I've a react app that always returns the same html page and that handles invalid routes within the app I want to make every request to my webpage return the exact same index.html (no matter what route the user asks for, '/' --> index.html '/test/test/test/test' --> index.html and so on.
Anyone have any ideas how I can do this? I've run out of google results
Thanks in advance!
Below is my entire server as of right now:
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
app.use('/build', express.static('build'));
io.on('connection', function(socket){
console.log('Connected');
});
http.listen(3000, function(){
console.log('listening on *:3000');
});