Serve Static Files on a Dynamic Route using Express

Okay. I found an example in the source code for Express’ response object. This is a slightly modified version of that example.

app.get('/user/:uid/files/*', function(req, res){
    var uid = req.params.uid,
        path = req.params[0] ? req.params[0] : 'index.html';
    res.sendFile(path, {root: './public'});
});

It uses the res.sendFile method.

NOTE: security changes to sendFile require the use of the root option.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)