I have a express app running on a node and would like the index.html to be presented to the client no matter the url location.
Example: http://example.com
should present the same page as: http://example.com/test
Current code:
var express = require('express');
var app = express();
var server = require('http').Server(app);
var path = require('path');
var port = process.env.PORT || 8000
app.use(express.static(path.join(__dirname, 'public')));
server.listen(port);
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
If you don't want to specify a route you can just use app.use:
app.use(function (req, res) {
res.sendFile(__dirname + "/public/index.html");
});