I would like to use expressjs sendfile to send the file from the parent directory of the script file. I tried to do this:
app.get('/', function(req, res){ res.sendfile('../../index.html'); });
I get a forbidden error because apparently the sendfile does not trust path traversal. So far, I have not been able to figure out how to change the directory of files sent via sendfile. Any clues?
Edit: I was tired when I published this, in fact it is easy. I will leave it here if anyone else stumbles upon this. There is an option parameter for sendfile that allows you to do this, for example:
app.get( '/', function( req, res ){ res.sendfile('index.html', { root: "../../"}); });
Silvester
source share