Skip to content

Commit

Permalink
basic 404 handler, #13
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Nov 19, 2015
1 parent 1c5fafb commit 7518b68
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ errorHandler = (err, req, res, next) ->
log.error "ERROR", StringifySafe err
delete err.arguments
res.status 400
if Accepts(req).types().length > 0 and Accepts(req).types()[0] is 'text/html'
if Accepts(req).type('text/html')
return res.render 'error', { err }
else
res.send StringifySafe err, null, 2

notFoundHandler = (req, res) ->
if Accepts(req).type('text/html')
return res.render '404', {reqJSON: StringifySafe(req, null, 2)}
else
res.end()



accessLogger = Morgan 'combined', stream: Fs.createWriteStream(__dirname + '/../data/logs/access.log', {flags: 'a'})
accessLoggerDev = Morgan 'dev'

Expand Down Expand Up @@ -122,6 +130,7 @@ class InfolisWebservice
res.end()
# Error handler
@app.use errorHandler
@app.use notFoundHandler

startServer : () ->
log.info "Setting up routes"
Expand Down
12 changes: 12 additions & 0 deletions views/404.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends ./layout.jade

block title
| 404 Not Found

block content
- req = JSON.parse(reqJSON)
.row
.col-md-offset-1
h1 404 Not Found
p There is no such thing
pre= JSON.stringify(req.headers, null, 2)

0 comments on commit 7518b68

Please sign in to comment.