Skip to content

Commit

Permalink
feature: error from serve displayed in the browser
Browse files Browse the repository at this point in the history
  • Loading branch information
zaiste committed Jan 14, 2017
1 parent 0d2608b commit 9499e90
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

const koa = require('koa');
const static = require('koa-static');
const error = require('koa-error');
const chokidar = require('chokidar');
const { compile, transformViews, compileAll } = require('./compiler');
const path = require('path');
Expand Down Expand Up @@ -43,11 +44,14 @@ function serve({ port, dir }) {
.on('change', recompile)

const app = koa();
app.use(error({
engine: 'nunjucks',
template: path.join(__dirname, '..', 'views', 'error.html')
}));
app.use(static('public'));

app.on('error', err => {
console.log('Error: '.red + err.message);
process.exit(1);
});

app.listen(port);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"gray-matter": "^2.1.0",
"js-yaml": "^3.7.0",
"koa": "^1.2.4",
"koa-error": "^2.1.0",
"koa-static": "^2.0.0",
"marked": "^0.3.6",
"node-sass": "^3.10.1",
Expand Down
26 changes: 26 additions & 0 deletions views/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>Error - {{status}}</title>
</head>
<body>
<div id="error">
<h1>Error</h1>
<p>Looks like something broke!</p>
{% if env == 'development' %}
<h2>Message:</h2>
<pre>
<code>
{{error}}
</code>
</pre>
<h2>Stack:</h2>
<pre>
<code>
{{stack}}
</code>
</pre>
{% endif %}
</div>
</body>
</html>

0 comments on commit 9499e90

Please sign in to comment.