I am trying to fetch web pages using express static and below is the server code.
app.use(express.static('DIR/webfiles'));
app.get('/test', function(req, res) {
console.log("got req");
res.sendfile("login.html");
});
app.get('/', function(req, res) {
console.log("got req");
res.sendfile("login.html");
});
when I request for localhost:port/test (from browser), I am able to see login.html page and it prints "got req" on server end but when I request for localhost:port or localhost:port/ , I am getting some other file in webfiles folder. It does not print "got req". Is empty GET handler overridden by express static?
When I remove "app.use(express.static('DIR/webfiles'));" line, it is able to get empty GET request but doesn't work in way I want it to. Why it is not getting empty request and how to handle empty requests.
localhost:portrequest automatically adds/to your request by default, which then becomeslocalhost:port/. So practically speaking you should getloginpage and not some other file.path = require ('path')then use the__dirnameandpath.join()on your directory. That will ensure you hit your static target directory.