Bladeren bron

整理目录结构

zhanwencai 1 jaar geleden
bovenliggende
commit
57561ee3da

+ 43 - 0
webServer/node_modules/koa2-cors/LICENSE

@@ -0,0 +1,43 @@
+MIT License
+
+Copyright (c) 2016 朱博文
+
+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 software is licensed under the MIT License.
+
+Copyright (c) 2015 - 2016 koajs and other 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.

+ 72 - 0
webServer/node_modules/koa2-cors/README.md

@@ -0,0 +1,72 @@
+# koa2-cors
+
+## install
+
+> it requires node v7.6.0 or higher now
+
+```bash
+npm install --save koa2-cors
+```
+
+## Usage
+
+```js
+var Koa = require('koa');
+var cors = require('koa2-cors');
+
+var app = new Koa();
+app.use(cors());
+```
+
+## Options
+
+### origin
+
+Configures the **Access-Control-Allow-Origin** CORS header. expects a string. Can also be set to a function, which takes the `ctx` as the first parameter.
+
+### exposeHeaders
+
+Configures the **Access-Control-Expose-Headers** CORS header. Expects a comma-delimited array.
+
+### maxAge
+
+Configures the **Access-Control-Max-Age** CORS header. Expects a
+Number.
+
+### credentials
+
+Configures the **Access-Control-Allow-Credentials** CORS header. Expects a Boolean.
+
+### allowMethods
+
+Configures the **Access-Control-Allow-Methods** CORS header. Expects a comma-delimited array , If not specified, default allowMethods is `['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']`.
+
+### allowHeaders
+Configures the **Access-Control-Allow-Headers** CORS header. Expects a comma-delimited array . If not specified, defaults to reflecting the headers specified in the request's **Access-Control-Request-Headers** header.
+
+```js
+var Koa = require('koa');
+var cors = require('koa2-cors');
+
+var app = new Koa();
+app.use(cors({
+  origin: function(ctx) {
+    if (ctx.url === '/test') {
+      return false;
+    }
+    return '*';
+  },
+  exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
+  maxAge: 5,
+  credentials: true,
+  allowMethods: ['GET', 'POST', 'DELETE'],
+  allowHeaders: ['Content-Type', 'Authorization', 'Accept'],
+}));
+...
+```
+
+[More details about CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS).
+
+## License
+
+[MIT License](http://www.opensource.org/licenses/mit-license.php)

+ 97 - 0
webServer/node_modules/koa2-cors/dist/index.js

@@ -0,0 +1,97 @@
+/**
+ * CORS middleware for koa2
+ *
+ * @param {Object} [options]
+ *  - {String|Function(ctx)} origin `Access-Control-Allow-Origin`, default is request Origin header
+ *  - {Array} exposeHeaders `Access-Control-Expose-Headers`
+ *  - {String|Number} maxAge `Access-Control-Max-Age` in seconds
+ *  - {Boolean} credentials `Access-Control-Allow-Credentials`
+ *  - {Array} allowMethods `Access-Control-Allow-Methods`,
+ *    default is ['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']
+ *  - {Array} allowHeaders `Access-Control-Allow-Headers`
+ * @return {Function}
+ * @api public
+ */
+module.exports = function crossOrigin(options = {}) {
+  const defaultOptions = {
+    allowMethods: ['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']
+  };
+
+  // set defaultOptions to options
+  options = Object.assign({}, defaultOptions, options); // eslint-disable-line no-param-reassign
+
+  // eslint-disable-next-line consistent-return
+  return async function cors(ctx, next) {
+    // always set vary Origin Header
+    // https://github.com/rs/cors/issues/10
+    ctx.vary('Origin');
+
+    let origin;
+    if (typeof options.origin === 'function') {
+      origin = options.origin(ctx);
+    } else {
+      origin = options.origin || ctx.get('Origin') || '*';
+    }
+    if (!origin) {
+      return await next();
+    }
+
+    // Access-Control-Allow-Origin
+    ctx.set('Access-Control-Allow-Origin', origin);
+
+    if (ctx.method === 'OPTIONS') {
+      // Preflight Request
+      if (!ctx.get('Access-Control-Request-Method')) {
+        return await next();
+      }
+
+      // Access-Control-Max-Age
+      if (options.maxAge) {
+        ctx.set('Access-Control-Max-Age', String(options.maxAge));
+      }
+
+      // Access-Control-Allow-Credentials
+      if (options.credentials === true) {
+        // When used as part of a response to a preflight request,
+        // this indicates whether or not the actual request can be made using credentials.
+        ctx.set('Access-Control-Allow-Credentials', 'true');
+      }
+
+      // Access-Control-Allow-Methods
+      if (options.allowMethods) {
+        ctx.set('Access-Control-Allow-Methods', options.allowMethods.join(','));
+      }
+
+      // Access-Control-Allow-Headers
+      if (options.allowHeaders) {
+        ctx.set('Access-Control-Allow-Headers', options.allowHeaders.join(','));
+      } else {
+        ctx.set('Access-Control-Allow-Headers', ctx.get('Access-Control-Request-Headers'));
+      }
+
+      ctx.status = 204; // No Content
+    } else {
+      // Request
+      // Access-Control-Allow-Credentials
+      if (options.credentials === true) {
+        if (origin === '*') {
+          // `credentials` can't be true when the `origin` is set to `*`
+          ctx.remove('Access-Control-Allow-Credentials');
+        } else {
+          ctx.set('Access-Control-Allow-Credentials', 'true');
+        }
+      }
+
+      // Access-Control-Expose-Headers
+      if (options.exposeHeaders) {
+        ctx.set('Access-Control-Expose-Headers', options.exposeHeaders.join(','));
+      }
+
+      try {
+        await next();
+      } catch (err) {
+        throw err;
+      }
+    }
+  };
+};

+ 74 - 0
webServer/node_modules/koa2-cors/package.json

@@ -0,0 +1,74 @@
+{
+  "_from": "koa2-cors",
+  "_id": "koa2-cors@2.0.6",
+  "_inBundle": false,
+  "_integrity": "sha512-JRCcSM4lamM+8kvKGDKlesYk2ASrmSTczDtGUnIadqMgnHU4Ct5Gw7Bxt3w3m6d6dy3WN0PU4oMP43HbddDEWg==",
+  "_location": "/koa2-cors",
+  "_phantomChildren": {},
+  "_requested": {
+    "type": "tag",
+    "registry": true,
+    "raw": "koa2-cors",
+    "name": "koa2-cors",
+    "escapedName": "koa2-cors",
+    "rawSpec": "",
+    "saveSpec": null,
+    "fetchSpec": "latest"
+  },
+  "_requiredBy": [
+    "#USER",
+    "/"
+  ],
+  "_resolved": "https://registry.npmmirror.com/koa2-cors/-/koa2-cors-2.0.6.tgz",
+  "_shasum": "9ad23df3a0b9bb84530b46f5944f3fb576086554",
+  "_spec": "koa2-cors",
+  "_where": "/Users/zhanwencai/code/game/congkong/webServer",
+  "author": {
+    "name": "zad"
+  },
+  "bugs": {
+    "url": "https://github.com/zadzbw/koa2-cors/issues"
+  },
+  "bundleDependencies": false,
+  "deprecated": false,
+  "description": "cors middleware for koa2",
+  "devDependencies": {
+    "babel-cli": "^6.18.0",
+    "chai": "^4.1.2",
+    "eslint": "^5.1.0",
+    "eslint-config-airbnb-base": "^13.0.0",
+    "eslint-plugin-import": "^2.13.0",
+    "istanbul": "^1.1.0-alpha.1",
+    "koa": "^2.5.2",
+    "koa-router": "^7.4.0",
+    "mocha": "^5.2.0",
+    "supertest": "^3.1.0"
+  },
+  "engines": {
+    "node": ">= 7.6.0"
+  },
+  "files": [
+    "src/index.js",
+    "dist/index.js"
+  ],
+  "homepage": "https://github.com/zadzbw/koa2-cors#readme",
+  "keywords": [
+    "koa2",
+    "cors",
+    "middleware"
+  ],
+  "license": "MIT",
+  "main": "dist/index.js",
+  "name": "koa2-cors",
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/zadzbw/koa2-cors.git"
+  },
+  "scripts": {
+    "build": "NODE_ENV=production rm -rf dist & babel src -d dist",
+    "lint": "eslint --ext .js src --format codeframe",
+    "test": "NODE_ENV=test mocha",
+    "test:cover": "NODE_ENV=test istanbul cover _mocha"
+  },
+  "version": "2.0.6"
+}

+ 97 - 0
webServer/node_modules/koa2-cors/src/index.js

@@ -0,0 +1,97 @@
+/**
+ * CORS middleware for koa2
+ *
+ * @param {Object} [options]
+ *  - {String|Function(ctx)} origin `Access-Control-Allow-Origin`, default is request Origin header
+ *  - {Array} exposeHeaders `Access-Control-Expose-Headers`
+ *  - {String|Number} maxAge `Access-Control-Max-Age` in seconds
+ *  - {Boolean} credentials `Access-Control-Allow-Credentials`
+ *  - {Array} allowMethods `Access-Control-Allow-Methods`,
+ *    default is ['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']
+ *  - {Array} allowHeaders `Access-Control-Allow-Headers`
+ * @return {Function}
+ * @api public
+ */
+module.exports = function crossOrigin(options = {}) {
+  const defaultOptions = {
+    allowMethods: ['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
+  };
+
+  // set defaultOptions to options
+  options = Object.assign({}, defaultOptions, options); // eslint-disable-line no-param-reassign
+
+  // eslint-disable-next-line consistent-return
+  return async function cors(ctx, next) {
+    // always set vary Origin Header
+    // https://github.com/rs/cors/issues/10
+    ctx.vary('Origin');
+
+    let origin;
+    if (typeof options.origin === 'function') {
+      origin = options.origin(ctx);
+    } else {
+      origin = options.origin || ctx.get('Origin') || '*';
+    }
+    if (!origin) {
+      return await next();
+    }
+
+    // Access-Control-Allow-Origin
+    ctx.set('Access-Control-Allow-Origin', origin);
+
+    if (ctx.method === 'OPTIONS') {
+      // Preflight Request
+      if (!ctx.get('Access-Control-Request-Method')) {
+        return await next();
+      }
+
+      // Access-Control-Max-Age
+      if (options.maxAge) {
+        ctx.set('Access-Control-Max-Age', String(options.maxAge));
+      }
+
+      // Access-Control-Allow-Credentials
+      if (options.credentials === true) {
+        // When used as part of a response to a preflight request,
+        // this indicates whether or not the actual request can be made using credentials.
+        ctx.set('Access-Control-Allow-Credentials', 'true');
+      }
+
+      // Access-Control-Allow-Methods
+      if (options.allowMethods) {
+        ctx.set('Access-Control-Allow-Methods', options.allowMethods.join(','));
+      }
+
+      // Access-Control-Allow-Headers
+      if (options.allowHeaders) {
+        ctx.set('Access-Control-Allow-Headers', options.allowHeaders.join(','));
+      } else {
+        ctx.set('Access-Control-Allow-Headers', ctx.get('Access-Control-Request-Headers'));
+      }
+
+      ctx.status = 204; // No Content
+    } else {
+      // Request
+      // Access-Control-Allow-Credentials
+      if (options.credentials === true) {
+        if (origin === '*') {
+          // `credentials` can't be true when the `origin` is set to `*`
+          ctx.remove('Access-Control-Allow-Credentials');
+        } else {
+          ctx.set('Access-Control-Allow-Credentials', 'true');
+        }
+      }
+
+      // Access-Control-Expose-Headers
+      if (options.exposeHeaders) {
+        ctx.set('Access-Control-Expose-Headers', options.exposeHeaders.join(','));
+      }
+
+      try {
+        await next();
+      } catch (err) {
+        throw err;
+      }
+    }
+  };
+};