Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
162 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
test | ||
src | ||
Makefile | ||
assets | ||
contributing.md | ||
.editorconfig | ||
.travis.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
axis = require 'axis' | ||
rupture = require 'rupture' | ||
autoprefixer = require 'autoprefixer-stylus' | ||
|
||
module.exports = | ||
ignores: [ | ||
'**/layout.*' | ||
'**/_*' | ||
'.gitignore' | ||
'lib/**' | ||
'assets/**' | ||
'test/**' | ||
'*.md' # specific to this project | ||
'.editorconfig' | ||
'.npmignore' | ||
'.travis.yml' | ||
'Makefile' | ||
] | ||
stylus: | ||
use: [axis(), rupture(), autoprefixer()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
body | ||
background #F4F2F0 | ||
font-family "Helvetica Neue", HelveticaNeue, Helvetica, Arial, sans-serif | ||
|
||
svg, h1 | ||
margin .8em 2em | ||
|
||
h1 | ||
color #A49E9A | ||
font-weight 300 | ||
text-align center | ||
|
||
svg | ||
display block | ||
margin-left auto | ||
margin-right auto |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,46 @@ | ||
fs = require 'fs' | ||
path = require 'path' | ||
accepts = require 'accepts' | ||
|
||
###* | ||
* Configures options and returns a middleware function. | ||
* | ||
* @param {String} file - path to custom error page. Default 'lib/404.html' | ||
* @param {String} [file='public/index.html'] - path to custom error page. | ||
* @return {Function} middleware function | ||
### | ||
|
||
module.exports = (root, file) -> | ||
fallback = path.join(__dirname, '404.html') | ||
error_page = fallback | ||
|
||
if not file and root | ||
error_page = path.resolve(root) | ||
|
||
if file and root | ||
error_page = path.join(root, file) | ||
module.exports = (file = path.join(__dirname, '/../public/index.html')) -> | ||
if arguments.length > 1 | ||
# support passing `root` as first arg for backwards compatibility. remove | ||
# this later | ||
file = path.join(arguments...) | ||
|
||
return (err, req, res, next) -> | ||
res.statusCode = 404 | ||
res.setHeader('Content-Type', 'text/html') | ||
res.statusCode = ( | ||
if err.status | ||
err.status | ||
else if res.statusCode < 400 | ||
500 | ||
) | ||
accept = accepts(req) | ||
|
||
if not fs.lstatSync(error_page).isDirectory() | ||
res.write(fs.readFileSync(error_page)) | ||
else | ||
res.write(fs.readFileSync(fallback)) | ||
if accept.type('html') | ||
fs.readFile file, 'utf8', (err, html) -> | ||
if err | ||
res.statusCode = 500 | ||
next(err) | ||
else | ||
res.setHeader 'Content-Type', 'text/html; charset=utf-8' | ||
res.end html | ||
else if accept.type('json') | ||
error = | ||
message: err.message | ||
stack: err.stack | ||
|
||
res.end() | ||
for prop of err | ||
continue | ||
json = JSON.stringify(error: error) | ||
res.setHeader 'Content-Type', 'application/json' | ||
res.end json | ||
else | ||
# send plain text | ||
res.setHeader 'Content-Type', 'text/plain' | ||
res.end err.stack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
{ | ||
"name": "apology-middleware", | ||
"description": "middleware for custom error pages", | ||
"version": "0.0.4", | ||
"author": "Carrot Creative <dev@carrotcreative.com>", | ||
"description": "middleware for custom error pages", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/kylemac/apology-middleware.git" | ||
"dependencies": { | ||
"accepts": "^1.0.2" | ||
}, | ||
"main": "lib", | ||
"devDependencies": { | ||
"mocha": "*", | ||
"alchemist-middleware": "0.0.4", | ||
"autoprefixer-stylus": "0.1.x", | ||
"axis": "0.2.x", | ||
"chai": "*", | ||
"chai-http": "*", | ||
"coffee-script": "1.7.x", | ||
"coffeelint": "*", | ||
"connect": "2.15.x", | ||
"coveralls": "*", | ||
"istanbul": "*", | ||
"jade": "1.x", | ||
"marked": "0.3.x", | ||
"mocha": "*", | ||
"mocha-lcov-reporter": "*", | ||
"coffee-script": "1.7.x", | ||
"connect": "2.15.x" | ||
"rupture": "0.1.x", | ||
"stylus": "0.45.x" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"license": "MIT", | ||
"main": "lib", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/carrot/apology-middleware.git" | ||
}, | ||
"scripts": { | ||
"test": "npm run lint && mocha", | ||
"lint": "find lib/ -name '*.coffee' | xargs coffeelint", | ||
"coverage": "make build; istanbul cover _mocha --report html -- -R spec && open coverage/index.html && make unbuild", | ||
"coveralls": "make build; istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage; make unbuild" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"dependencies": { | ||
"coveralls": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html><html><head><meta charset="utf8"><meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"><meta name="viewport" content="width=device-width"><title>Uh oh...</title></head><body><style>body { | ||
background: #f4f2f0; | ||
font-family: "Helvetica Neue", HelveticaNeue, Helvetica, Arial, sans-serif; | ||
} | ||
svg, | ||
h1 { | ||
margin: 0.8em 2em; | ||
} | ||
h1 { | ||
color: #a49e9a; | ||
font-weight: 300; | ||
text-align: center; | ||
} | ||
svg { | ||
display: block; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
</style><script>(function() { | ||
|
||
|
||
}).call(this); | ||
</script><svg width="68" height="68" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M0 34c0 18.785 15.215 34 34 34s34-15.215 34-34-15.215-34-34-34-34 15.215-34 34zm44.572-17l6.428 6.46-10.53 10.625 10.403 10.408-6.47 6.507-10.403-10.459-10.361 10.459-6.47-6.507 10.403-10.408-10.572-10.625 6.47-6.46 10.53 10.574 10.572-10.574z" fill="#C2471B"></path> | ||
</svg> | ||
<h1>Something went wrong : (</h1></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extends layout | ||
|
||
block content | ||
style | ||
include:stylus ../assets/css/index.styl | ||
script | ||
include:coffee ../assets/js/index.coffee | ||
|
||
include ../assets/img/error-icon.svg | ||
h1 Something went wrong : ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
doctype html | ||
html | ||
head | ||
meta(charset='utf8') | ||
meta(http-equiv='X-UA-Compatible', content='IE=edge, chrome=1') | ||
meta(name='viewport', content='width=device-width') | ||
title Uh oh... | ||
body | ||
block content |