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:
commit
d74b59c701
35
server.js
35
server.js
@ -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
11
views/error.jade
Normal 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}
|
Loading…
Reference in New Issue
Block a user