portertech/tails — Issue #3: req.uriParams.file does not contain the extensions to load *.js, *.css & *.png
Author: theho
Created: 2011-10-23 06:21:53+00:00
State: open

```javascript
api.get('/:dir/:file', function(req, res) {
fs.readFile(__dirname + '/public/' + req.uriParams.dir + '/' + req.uriParams.file + , function (err, file) {
if (err) {
res.send(404)
}
res.send({code: 200, headers: {'Content-Type': mime.lookup(req.uriParams.file)}, noEnd: true})
res.end(file)
})
})
```
Seems that restify doesn't support express like routes. As such req.uriParams.file does not contain the file extensions for .js .css and .png files.

Below is an ugly hack:

```javascript

api.get('/:dir/:file', function(req, res) {

var ext = '';

switch(req.uriParams.dir) {
case 'images':
ext = '.png';
break;
case 'scripts':
ext = '.js';
break;
case 'stylesheets':
ext = '.css';
break;
}

fs.readFile(__dirname + '/public/' + req.uriParams.dir + '/' + req.uriParams.file + ext, function (err, file) {
if (err) {
console.log(req.uriParams);
res.send(404)
}
res.send({code: 200, headers: {'Content-Type': mime.lookup(req.uriParams.file + ext)}, noEnd: true})
res.end(file)
})
})
```

note -- I've also tried using RegEx instead (/^\/images|scripts|stylesheets\/*/...) but restify still barfs.

Thanks for the tails app.