Skip to content

Instantly share code, notes, and snippets.

@mcavage
Created June 30, 2011 14:57
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mcavage/1056404 to your computer and use it in GitHub Desktop.
Save mcavage/1056404 to your computer and use it in GitHub Desktop.
Serving static content with restify
// Docs/etc.
server.get(null, '/', function(request, response, next) {
response.send(302, null, {
Location: config.siteName + '/docs'
});
return next();
}, log.w3c);
server.get(null, '/docs', function(req, res, next) {
fs.readFile('./docs/index.html', 'utf8', function(err, file) {
if (err) {
res.send(500);
return next();
}
res.send({
code: 200,
noEnd: true
});
res.write(file);
res.end();
return next();
});
}, log.w3c);
server.get(null, '/favicon.ico', function(req, res, next) {
fs.readFile('./docs/media/img/favicon.ico', function(err, file) {
if (err) {
res.send(500);
return next();
}
res.send({
code: 200,
noEnd: true
});
res.write(file);
res.end();
return next();
});
}, log.w3c);
server.get(null, /^\/media\/css\/*/, function(req, res, next) {
fs.readFile('./docs' + req.url, 'utf8', function(err, file) {
if (err) {
res.send(500);
return next();
}
res.send({
code: 200,
noEnd: true
});
res.write(file);
res.end();
return next();
});
}, log.w3c);
server.get(null, /^\/media\/img\/*/, function(req, res, next) {
fs.readFile('./docs' + req.url, function(err, file) {
if (err) {
res.send(500);
return next();
}
res.send({
code: 200,
noEnd: true
});
res.write(file);
res.end();
return next();
});
}, log.w3c);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment