1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-22 09:12:19 -05:00

Merge pull request #10 from cblage/master

Custom error handling and removal of fs.readFileSync
This commit is contained in:
Lance Stout 2013-10-20 16:42:30 -07:00
commit d74b59c701
2 changed files with 44 additions and 6 deletions

View File

@ -68,20 +68,47 @@ app.get('/oauth/callback', function (req, res) {
res.render('oauthLogin');
});
app.get('/manifest.webapp', function (req, res) {
app.get('/manifest.webapp', function (req, res, next) {
fs.readFile('./public/x-manifest.webapp', function doneReadingManifest(err, manifestContents) {
if (err) return next(err);
res.set('Content-Type', 'application/x-web-app-manifest+json');
res.send(fs.readFileSync('./public/x-manifest.webapp'));
res.send(manifestContents);
});
});
app.get('/manifest.cache', function (req, res) {
app.get('/manifest.cache', function (req, res, next) {
fs.readFile('./public/x-manifest.cache', function doneReadingManifestCache(err, manifestCacheContents) {
if (err) return next(err);
res.set('Content-Type', 'text/cache-manifest');
res.send(fs.readFileSync('./public/x-manifest.cache'));
res.send(manifestCacheContents);
});
});
// serves app on every other url
app.get('*', clientApp.html());
app.use(function handleError(err, req, res, next) {
var errorResult = {message: 'Something bad happened :('};
if (config.isDev) {
if (err instanceof Error) {
if (err.message) {
errorResult.message = err.message;
}
if (err.stack) {
errorResult.stack = err.stack;
}
}
}
res.status(500);
res.render('error', errorResult);
});
//https.createServer({
// key: fs.readFileSync(config.http.key),
// cert: fs.readFileSync(config.http.cert)

11
views/error.jade Normal file
View File

@ -0,0 +1,11 @@
extends layout
block content
section#errorBox.content.box
.head
h2 Oops, something went wrong!
.content
p #{message}
if stack
pre #{stack}