Reputation: 23
app.get(`/`, (req, res, next) => {
console.log(`in / get`);
const indexHtml = path.resolve( __dirname + '/../public/index.html' );
res.sendFile(indexHtml);
next();
});
I'm trying to make this index.html show up on my home route using express but it's not loading. I get the console log, and I've console logged indexHTML to ensure the path is correct, but all I get is an error of cannot get. All my other routes that are brought it are working a-ok. Just not this guy.
Upvotes: 0
Views: 267
Reputation: 707376
Remove the call to next()
after res.sendFile()
. You want the res.sendFile()
to handle the response entirely, but calling next()
passes on control to other handlers, probably ending up in the 404 handler and because that doesn't have to read the disk, it gets processed before res.sendFile()
does it's job.
When you send the response, you do not want to call next()
because you don't want any more request handlers in the chain to run.
Upvotes: 1