My file structure:
- simulated-selves
- client
- index.html
- server
- app.js
I'm trying to send the user index.html when they hit the / route.
// server/app.js
app.get('/', function(req, res) {
res.sendFile(__dirname + '/../client/index.html', null, function(err) {
if (err) {
console.log('error: ', err);
res.status(err.status).end();
}
else res.status(200).end();
});
});
It's not working though. This is the error that gets logged out:
error: { [Error: Forbidden] status: 403 }
So basically I have access to __dirname in app.js. Since app.js is in the server folder, __dirname resolves to /Users/azerner/code/simulated-selves/server. Since I need to access index.html in the client folder, I need to manipulate this __dirname that I have. I know I could do some string manipulation, but I'm looking for the best way to do this.
/../client/index.html?/../client/index.html! It's still giving me the same error though. And yes - I've restarted my server.