Skip to content

Commit

Permalink
Re-added custom flag - defaults to false
Browse files Browse the repository at this point in the history
  • Loading branch information
ncrohn committed Jul 2, 2012
1 parent 7725305 commit 24a255c
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/lib/docpad.coffee
Expand Up @@ -356,6 +356,10 @@ class DocPad extends EventEmitterEnhanced
# Whether or not we should extend the server with extra middleware and routing
extendServer: true

# Enable Custom Error Pages
# A flag to provide an entry to handle custom error pages
useCustomErrors: false

# Port
# The port that the server should use
port: 9778
Expand Down Expand Up @@ -2483,25 +2487,31 @@ class DocPad extends EventEmitterEnhanced
# 404 Middleware
server.use (req, res, next) ->
notFound = 404
code = findClosest(notFound)
if errorFiles.hasOwnProperty(code) && pathUtil.existsSync errorFiles[code]
data = fsUtil.readFileSync(errorFiles[code], 'utf8')
else
data = notFound + ' ' + errorCodes[notFound]
if config.useCustomErrors
code = findClosest(notFound)
if errorFiles.hasOwnProperty(code) && pathUtil.existsSync errorFiles[code]
data = fsUtil.readFileSync(errorFiles[code], 'utf8')
else
data = notFound + ' ' + errorCodes[notFound]

return res.send(data, notFound)
return res.send(data, notFound)
else
return res.send(notFound)

# 500 Middleware
server.use (err, req, res, next) ->
# Assume 500 for now
serverError = 500
code = findClosest(serverError)
if errorFiles.hasOwnProperty(code) && pathUtil.existsSync errorFiles[code]
data = fsUtil.readFileSync(errorFiles[code], 'utf8')
else
data = serverError + ' ' + errorCodes[serverError]
if config.useCustomErrors
code = findClosest(serverError)
if errorFiles.hasOwnProperty(code) && pathUtil.existsSync errorFiles[code]
data = fsUtil.readFileSync(errorFiles[code], 'utf8')
else
data = serverError + ' ' + errorCodes[serverError]

return res.send(datam serverError)
return res.send(data, serverError)
else
res.send(serverError)

# Start the Server
startServer()
Expand Down

0 comments on commit 24a255c

Please sign in to comment.