Hello !
I have a file (among others) in a specific folder outside of nodebb (for example /toto/myfiles/filetoget ; nodebb executable is in /toto/nodebb folder).
I want to be able to download the /toto/myfiles/filetoget file with the route "/myfiles/filetoget". For this, I use the following code (in the static:app.load hook) in a plugin :
app.get('/myfiles/:file(*?)', function (req, res) {
// absolute path to the file to get
var absolutefile = path.dirname(process.cwd()) + '/myfiles/' + req.params.file;
if (fs.existsSync(absolutefile)) {
res.status(200);
res.sendFile(absolutefile);
} else {
console.log('File not found');
res.status(404);
res.render('404', {path: req.path});
}
});
It works when I full load page http://127.0.0.1:4567/myfiles/filetoget but it doesn't work when I click on a link with 'myfiles/filetoget' (showing also the full address http://127.0.0.1:4567/myfiles/filetoget on a nodebb page). I have a page of nodebb saying the page is not found and there is no particular message in the console.
How can I solve this problem ? (I do this because I will do other things (permissions...) before the download of the file in my plugin).
I will also link these files in admin/manage/categories/** as external link (I hope it's possible)...
If I use a wrong way, how can I make relative links (routes) in nodebb to files outer from nodebb folder ?
Thanks in advance for help !