Created
June 30, 2011 14:57
-
-
Save mcavage/1056404 to your computer and use it in GitHub Desktop.
Serving static content with restify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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