docs:更新文档

This commit is contained in:
张益铭
2021-03-01 15:06:11 +08:00
parent 1542135ab0
commit 9064b372e8
5835 changed files with 904126 additions and 161722 deletions

3
node_modules/koa-proxies/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# 0.0.1 - 2016-12-19
Initial release

21
node_modules/koa-proxies/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 vagusX
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.

1
node_modules/koa-proxies/_config.yml generated vendored Normal file
View File

@@ -0,0 +1 @@
theme: jekyll-theme-hacker

15
node_modules/koa-proxies/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,15 @@
import * as Koa from 'koa';
declare function KoaProxies(path: string, options: KoaProxies.IKoaProxiesOptions): Koa.Middleware;
declare namespace KoaProxies {
interface IKoaProxiesOptions {
target: string;
changeOrigin?: boolean;
logs?: boolean | ((ctx: Koa.Context, target: string) => void);
agent?: any;
rewrite?: (path: string) => string;
}
}
export = KoaProxies;

88
node_modules/koa-proxies/index.js generated vendored Normal file
View File

@@ -0,0 +1,88 @@
/**
* Dependencies
*/
const { URL } = require('url')
const HttpProxy = require('http-proxy')
const pathMatch = require('path-match')
/**
* Constants
*/
const proxy = HttpProxy.createProxyServer()
const route = pathMatch({
// path-to-regexp options
sensitive: false,
strict: false,
end: false
})
let eventRegistered = false
/**
* Koa Http Proxy Middleware
*/
module.exports = (path, options) => (ctx, next) => {
// create a match function
const match = route(path)
if (!match(ctx.path)) return next()
let opts = Object.assign({}, options)
if (typeof options === 'function') {
const params = match(ctx.path)
opts = options.call(options, params)
}
// object-rest-spread is still in stage-3
// https://github.com/tc39/proposal-object-rest-spread
const { logs, rewrite, events } = opts
const httpProxyOpts = Object.keys(opts)
.filter(n => ['logs', 'rewrite', 'events'].indexOf(n) < 0)
.reduce((prev, cur) => {
prev[cur] = opts[cur]
return prev
}, {})
return new Promise((resolve, reject) => {
ctx.req.oldPath = ctx.req.url
if (typeof rewrite === 'function') {
ctx.req.url = rewrite(ctx.req.url, ctx)
}
if (logs) {
typeof logs === 'function' ? logs(ctx, opts.target) : logger(ctx, opts.target)
}
if (events && typeof events === 'object' && !eventRegistered) {
Object.entries(events).forEach(([event, handler]) => {
proxy.on(event, handler)
})
eventRegistered = true
}
// Let the promise be solved correctly after the proxy.web.
// The solution comes from https://github.com/nodejitsu/node-http-proxy/issues/951#issuecomment-179904134
ctx.res.on('close', () => {
reject(new Error(`Http response closed while proxying ${ctx.req.oldPath}`))
})
ctx.res.on('finish', () => {
resolve()
})
proxy.web(ctx.req, ctx.res, httpProxyOpts, e => {
const status = {
ECONNREFUSED: 503,
ETIMEOUT: 504
}[e.code]
ctx.status = status || 500
resolve()
})
})
}
module.exports.proxy = proxy
function logger (ctx, target) {
console.log('%s - %s %s proxy to -> %s', new Date().toISOString(), ctx.req.method, ctx.req.oldPath, new URL(ctx.req.url, target))
}

101
node_modules/koa-proxies/package.json generated vendored Normal file
View File

@@ -0,0 +1,101 @@
{
"_args": [
[
"koa-proxies@0.11.0",
"J:\\Github\\CURD-TS"
]
],
"_development": true,
"_from": "koa-proxies@0.11.0",
"_id": "koa-proxies@0.11.0",
"_inBundle": false,
"_integrity": "sha1-Q93kJgCA98sPKEZV+Fz2VLvp7IQ=",
"_location": "/koa-proxies",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "koa-proxies@0.11.0",
"name": "koa-proxies",
"escapedName": "koa-proxies",
"rawSpec": "0.11.0",
"saveSpec": null,
"fetchSpec": "0.11.0"
},
"_requiredBy": [
"/vite"
],
"_resolved": "http://192.168.250.101:4873/koa-proxies/-/koa-proxies-0.11.0.tgz",
"_spec": "0.11.0",
"_where": "J:\\Github\\CURD-TS",
"author": {
"name": "vagusX"
},
"bugs": {
"url": "https://github.com/vagusX/koa-proxies/issues"
},
"dependencies": {
"http-proxy": "^1.16.2",
"path-match": "^1.2.4"
},
"description": "Http Proxy Middleware for Koa@2.x/next",
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"@types/koa": "^2.11.0",
"chai": "^4.1.2",
"chai-http": "^4.0.0",
"codecov": "^3.0.4",
"eslint": "^6.5.1",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-mocha": "^6.1.1",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"ghooks": "^2.0.2",
"husky": "^3.0.8",
"koa": "^2.5.2",
"lint-staged": "^10.0.0-0",
"mocha": "^6.0.0",
"nyc": "^12.0.2",
"semantic-release": "^15.1.5",
"sinon": "^7.2.4",
"sinon-chai": "^3.4.0"
},
"homepage": "https://github.com/vagusX/koa-proxies#readme",
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"keywords": [
"koa",
"middleware",
"proxy",
"proxies"
],
"license": "MIT",
"lint-staged": {
"*.js": "npm run lint"
},
"main": "index.js",
"name": "koa-proxies",
"peerDependencies": {
"koa": ">=2"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vagusX/koa-proxies.git"
},
"scripts": {
"ci": "npm run test && npm run coverage",
"coverage": "nyc report --reporter=lcov --reporter=html && codecov -f .nyc_output/*.json",
"lint": "eslint index.js test/",
"semantic-release": "semantic-release",
"test": "nyc mocha"
},
"typings": "index.d.ts",
"version": "0.11.0"
}

63
node_modules/koa-proxies/readme.md generated vendored Normal file
View File

@@ -0,0 +1,63 @@
# Koa Proxies
![NPM](https://img.shields.io/npm/v/koa-proxies.svg)
[![TavisCI Build](https://img.shields.io/travis/vagusX/koa-proxies.svg)](https://travis-ci.org/vagusX/koa-proxies)
[![CircieCI Build](https://img.shields.io/circleci/project/github/vagusX/koa-proxies.svg)](https://circleci.com/gh/vagusX/koa-proxies)
[![Coverage](https://img.shields.io/codecov/c/github/vagusX/koa-proxies.svg)](https://codecov.io/gh/vagusX/koa-proxies)
[![NPM Downloads](https://img.shields.io/npm/dm/koa-proxies.svg)](https://www.npmjs.com/package/koa-proxies)
[![Greenkeeper badge](https://badges.greenkeeper.io/vagusX/koa-proxies.svg)](https://greenkeeper.io/)
> [Koa@2.x/next](https://github.com/koajs/koa) middlware for http proxy
Powered by [`http-proxy`](https://github.com/nodejitsu/node-http-proxy).
## Installation
```bash
$ npm install koa-proxies --save
```
## Options
### http-proxy events
```js
options.events = {
error (err, req, res) { },
proxyReq (proxyReq, req, res) { },
proxyRes (proxyRes, req, res) { }
}
```
### log option
```js
// enable log
options.logs = true; // or false
// custom log function
options.logs = (ctx, opts.target) {
console.log('%s - %s %s proxy to -> %s', new Date().toISOString(), ctx.req.method, ctx.req.oldPath, new URL(ctx.req.url, target))
}
```
## Usage
```js
// dependencies
const Koa = require('koa')
const proxy = require('koa-proxies')
const httpsProxyAgent = require('https-proxy-agent')
const app = new Koa()
// middleware
app.use(proxy('/octocat', {
target: 'https://api.github.com/users',
changeOrigin: true,
agent: new httpsProxyAgent('http://1.2.3.4:88'), // if you need or just delete this line
rewrite: path => path.replace(/^\/octocat(\/|\/\w+)?$/, '/vagusx'),
logs: true
}))
```
[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)