-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add LICENSE π .. * update README.md π .. * update .gitignore file π .. * add eslintrc(s) β’οΈ .. * add eslint to pkg.json π .. * run lint --eslint π π» .. * ES6+: add string template over '' π .. * add test coverage π¦ .. * update some depen. πͺ.. * update the CI pipeline π² .. * update pkg --pathToRegExp π .. * better stuctrue π ..
- Loading branch information
1 parent
fad904d
commit 2c6ce82
Showing
10 changed files
with
219 additions
and
147 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
extends: standard |
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 +1,23 @@ | ||
# OS # | ||
################### | ||
.DS_Store | ||
.idea | ||
Thumbs.db | ||
tmp/ | ||
temp/ | ||
|
||
|
||
# Node.js # | ||
################### | ||
node_modules | ||
package-lock.json | ||
npm-debug.log | ||
yarn-debug.log | ||
yarn-error.log | ||
|
||
|
||
# NYC # | ||
################### | ||
coverage | ||
*.lcov | ||
.nyc_output |
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,3 +1,12 @@ | ||
node_js: | ||
- 8 | ||
language: node_js | ||
node_js: | ||
- 8 | ||
- 10 | ||
- 12 | ||
- 'lts/*' | ||
- 'node' | ||
script: | ||
- npm run test-cov | ||
after_script: | ||
- npm i coveralls | ||
- cat ./coverage/lcov.info | node ./node_modules/coveralls/bin/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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Koa contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,50 +1,50 @@ | ||
# [**koa-rewrite**](https://github.com/koajs/rewrite) | ||
|
||
# koa-rewrite | ||
|
||
URL rewrite middleware for koa. | ||
> URL rewrite middleware for koa. | ||
___Notice: `koa-rewrite@2+` supports `koa@2`, if you want to use this module with `koa@1`, please use `koa-rewrite@1`.___ | ||
|
||
|
||
## Installation | ||
|
||
```js | ||
$ npm install koa-rewrite | ||
``` | ||
|
||
|
||
## Examples | ||
|
||
Rewrite using a regular expression, rewriting | ||
`/i123` to `/items/123`. | ||
Rewrite using a regular expression, rewriting `/i123` to `/items/123`. | ||
|
||
```js | ||
app.use(rewrite(/^\/i(\w+)/, '/items/$1')); | ||
``` | ||
|
||
Rewrite using route parameters, references may be named | ||
or numeric. For example rewrite `/foo..bar` to `/commits/foo/to/bar`: | ||
Rewrite using route parameters, references may be named or numeric. For example rewrite `/foo..bar` to `/commits/foo/to/bar`: | ||
|
||
```js | ||
app.use(rewrite('/:src..:dst', '/commits/$1/to/$2')); | ||
app.use(rewrite('/:src..:dst', '/commits/:src/to/:dst')); | ||
``` | ||
|
||
You may also use the wildcard `*` to soak up several segments, | ||
for example `/js/vendor/jquery.js` would become `/public/assets/js/vendor/jquery.js`: | ||
You may also use the wildcard `*` to soak up several segments, for example `/js/vendor/jquery.js` would become `/public/assets/js/vendor/jquery.js`: | ||
|
||
```js | ||
app.use(rewrite('/js/(.*)', '/public/assets/js/$1')); | ||
``` | ||
|
||
|
||
## Debugging | ||
|
||
Use the __DEBUG__ environment variable with "koa-rewrite": | ||
Use the __DEBUG__ environment variable with "koa-rewrite": | ||
|
||
``` | ||
koa-rewrite rewrite /i123 -> /items/123 +762ms | ||
koa-rewrite rewrite /i321 -> /items/321 +9s | ||
koa-rewrite rewrite /i123 -> /items/123 +5s | ||
``` | ||
|
||
|
||
## License | ||
|
||
MIT | ||
[MIT](/LICENSE) |
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,24 +1,24 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
const rewrite = require('./'); | ||
const Koa = require('koa'); | ||
const rewrite = require('./') | ||
const Koa = require('koa') | ||
|
||
const app = new Koa(); | ||
const app = new Koa() | ||
|
||
// GET /i124 | ||
app.use(rewrite(/^\/i(\w+)/, '/items/$1')); | ||
app.use(rewrite(/^\/i(\w+)/, '/items/$1')) | ||
|
||
// GET /foo..bar | ||
//app.use(rewrite('/:src..:dst', '/commits/$1/to/$2')); | ||
app.use(rewrite('/:src..:dst', '/commits/:src/to/:dst')); | ||
// app.use(rewrite('/:src..:dst', '/commits/$1/to/$2')); | ||
app.use(rewrite('/:src..:dst', '/commits/:src/to/:dst')) | ||
|
||
// GET /js/jquery.js | ||
app.use(rewrite('/js/(.*)', '/public/assets/js/$1')); | ||
app.use(rewrite('/js/(.*)', '/public/assets/js/$1')) | ||
|
||
app.use(function(ctx) { | ||
ctx.body = ctx.url + '\n'; | ||
}); | ||
app.use(function (ctx) { | ||
ctx.body = `${ctx.url}\n` | ||
}) | ||
|
||
app.listen(3000, () => { | ||
console.log('listening on port 3000'); | ||
}); | ||
console.log('listening on port 3000') | ||
}) |
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
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,3 @@ | ||
--- | ||
env: | ||
mocha: true |
Oops, something went wrong.