Skip to content

Commit 48316f4

Browse files
committed
Initial commit
0 parents  commit 48316f4

11 files changed

+5837
-0
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
*.log
3+
.idea
4+
node_modules
5+
coverage
6+
.nyc_output

.remarkignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/snapshots/**/*.md

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- '8'
4+
after_success:
5+
npm run coverage

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# koa-404-handler
2+
3+
[![build status](https://img.shields.io/travis/ladjs/koa-404-handler.svg)](https://travis-ci.org/ladjs/koa-404-handler)
4+
[![code coverage](https://img.shields.io/codecov/c/github/ladjs/koa-404-handler.svg)](https://codecov.io/gh/ladjs/koa-404-handler)
5+
[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
6+
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
7+
[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org)
8+
[![license](https://img.shields.io/github/license/ladjs/koa-404-handler.svg)](<>)
9+
10+
> 404 handler for [Lad][] and [Koa][] (best used with [koa-better-error-handler][])
11+
12+
13+
## Table of Contents
14+
15+
* [Install](#install)
16+
* [Usage](#usage)
17+
* [Contributors](#contributors)
18+
* [License](#license)
19+
20+
21+
## Install
22+
23+
[npm][]:
24+
25+
```sh
26+
npm install koa-404-handler
27+
```
28+
29+
[yarn][]:
30+
31+
```sh
32+
yarn add koa-404-handler
33+
```
34+
35+
36+
## Usage
37+
38+
```js
39+
const errorHandler = require('koa-better-error-handler');
40+
const koa404Handler = require('koa-404-handler');
41+
42+
// ...
43+
44+
// override koa's undocumented error handler
45+
app.context.onerror = errorHandler;
46+
47+
// ... routes go here ...
48+
49+
app.use(koa404Handler);
50+
51+
app.listen();
52+
```
53+
54+
55+
## Contributors
56+
57+
| Name | Website |
58+
| -------------- | -------------------------- |
59+
| **Nick Baugh** | <http://niftylettuce.com/> |
60+
61+
62+
## License
63+
64+
[MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com/)
65+
66+
67+
##
68+
69+
[npm]: https://www.npmjs.com/
70+
71+
[yarn]: https://yarnpkg.com/
72+
73+
[lad]: https://lad.js.org
74+
75+
[koa]: http://koajs.com
76+
77+
[koa-better-error-handler]: https://github.com/ladjs/koa-better-error-handler

index.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const koa404Handler = async (ctx, next) => {
2+
try {
3+
await next();
4+
if (ctx.status === 404) ctx.throw(404);
5+
} catch (err) {
6+
ctx.throw(err);
7+
ctx.app.emit('error', err, ctx);
8+
}
9+
};
10+
11+
module.exports = koa404Handler;

package.json

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"name": "koa-404-handler",
3+
"description":
4+
"404 handler for Lad and Koa (best used with koa-better-error-handler)",
5+
"version": "0.0.1",
6+
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
7+
"bugs": {
8+
"url": "https://github.com/ladjs/koa-404-handler/issues",
9+
"email": "niftylettuce@gmail.com"
10+
},
11+
"contributors": [
12+
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)"
13+
],
14+
"dependencies": {},
15+
"devDependencies": {
16+
"ava": "^0.22.0",
17+
"codecov": "^2.3.0",
18+
"cross-env": "^5.0.5",
19+
"eslint": "^4.5.0",
20+
"eslint-config-prettier": "^2.3.0",
21+
"eslint-plugin-prettier": "^2.2.0",
22+
"husky": "^0.14.3",
23+
"lint-staged": "^4.0.4",
24+
"nyc": "^11.1.0",
25+
"prettier": "^1.6.1",
26+
"remark-cli": "^4.0.0",
27+
"remark-preset-github": "^0.0.6",
28+
"xo": "^0.19.0"
29+
},
30+
"engines": {
31+
"node": ">=6.4"
32+
},
33+
"homepage": "https://github.com/ladjs/koa-404-handler",
34+
"keywords": [
35+
"lad",
36+
"koa",
37+
"404",
38+
"handler",
39+
"error",
40+
"middleware",
41+
"ctx",
42+
"koa-404-handler",
43+
"lass"
44+
],
45+
"license": "MIT",
46+
"lint-staged": {
47+
"*.{js,jsx,mjs,ts,tsx,css,less,scss,json,graphql}": [
48+
"prettier --write --single-quote --trailing-comma none",
49+
"git add"
50+
],
51+
"*.md": ["remark . -qfo", "git add"]
52+
},
53+
"main": "index.js",
54+
"remarkConfig": {
55+
"plugins": ["preset-github"]
56+
},
57+
"repository": {
58+
"type": "git",
59+
"url": "https://github.com/ladjs/koa-404-handler"
60+
},
61+
"scripts": {
62+
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
63+
"lint": "xo && remark . -qfo",
64+
"precommit": "lint-staged && npm test",
65+
"test": "npm run lint && npm run test-coverage",
66+
"test-coverage": "cross-env NODE_ENV=test nyc ava"
67+
},
68+
"xo": {
69+
"extends": "prettier",
70+
"plugins": ["prettier"],
71+
"parserOptions": {
72+
"sourceType": "script"
73+
},
74+
"rules": {
75+
"prettier/prettier": [
76+
"error",
77+
{
78+
"singleQuote": true,
79+
"bracketSpacing": true,
80+
"trailingComma": "none"
81+
}
82+
],
83+
"max-len": [
84+
"error",
85+
{
86+
"code": 80,
87+
"ignoreUrls": true
88+
}
89+
],
90+
"capitalized-comments": "off",
91+
"camelcase": "off",
92+
"no-warning-comments": "off"
93+
},
94+
"space": true
95+
}
96+
}

test/test.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const test = require('ava');
2+
3+
const koa404Handler = require('../');
4+
5+
test('returns a function', t => {
6+
t.true(typeof koa404Handler === 'function');
7+
});

0 commit comments

Comments
 (0)