I am serving a PDF file on node server at this path – /content/assets/sample.pdf. I want to restrict unauthorize access to this PDF file. For that, I have applied the authentication to /content/assets/*
router.use('/content/assets/*', isAuthenticated, (req, res) => {
const filePath = path.join(__dirname, '../../static', req.path);
console.log(filePath);
res.sendFile(filePath);
});
function isAuthenticated(req, res, next) {
const userIsAuthenticated = true;
if (userIsAuthenticated) {
next();
} else {
res.status(403).send('Unauthorized');
}
}
When I try postman to check this, I am able to restrict /content/assets/ but not /content/assets/sample.pdf
Is there anything I can do to restrict the PDF file ?