From 70a2df558344a0179a426b201aaf07f7c2064932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Wed, 30 Sep 2020 14:25:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B7=A8=E5=9F=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE;=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.md | 6 +++--- config/index.js | 2 +- index.js | 2 ++ middleware/cors.js | 14 ++++++++++++-- package.json | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Readme.md b/Readme.md index 9e8872d..ab77d12 100644 --- a/Readme.md +++ b/Readme.md @@ -65,16 +65,16 @@ import Five from '@gm5/core' var app = new Five() app.set({ website: 'www.your_domain.com' }) -app.set({ domain: 'your_domain.com' }) // 设置域,cookie用到,不设置则同步website +// app.set({ domain: 'your_domain.com' }) // 设置域,cookie用到,不设置则等同于website -app.set({ VIEWS: './views/' }) // [可选], 但是要用到模板渲染页面时, 必须指定 +// app.set({ VIEWS: './views/' }) // [可选], 但是要用到模板渲染页面时, 必须指定 app.preload('./apps/') // [必须], 预加载应用目录 app.listen(3001) // 默认是3000 ``` -其他的配置和功能, 请参考 `文档`。 +其他的配置和功能, 请参考 [文档](https://github.com/bytedo/gmf.core/wiki)。 3. 启动应用。在项目根目录打开终端, 输入以下命令 `five-cli start`, 然后根据提示操作, 即可 diff --git a/config/index.js b/config/index.js index d5fb134..f8509cd 100644 --- a/config/index.js +++ b/config/index.js @@ -49,7 +49,7 @@ export default { enabled: false, credentials: false, origin: [], // ['abc.com', 'a.foo.com'] - maxAge: 0 + maxAge: 14400 }, regexp: { // 常用正则 diff --git a/index.js b/index.js index 30bcaca..43235b7 100644 --- a/index.js +++ b/index.js @@ -38,8 +38,10 @@ export default class Five { __main__() { var { domain, website, session, jwt } = this.__FIVE__ + domain = domain || website session.domain = session.domain || domain + this.set({ domain, session }) // 安装模板引擎 diff --git a/middleware/cors.js b/middleware/cors.js index 878221e..9637246 100644 --- a/middleware/cors.js +++ b/middleware/cors.js @@ -15,11 +15,21 @@ export default function(req, res, next) { var { hostname, host, protocol } = url.parse(origin) if (CORS.origin.length && hostname) { - if (!CORS.origin.includes(hostname)) { + var pass = false + for (let it of CORS.origin) { + if (hostname.endsWith(it)) { + pass = true + break + } + } + if (pass === false) { return res.end('') } } - res.set('Access-Control-Allow-Credentials', 'true') + if (CORS.credentials) { + res.set('Access-Control-Allow-Credentials', 'true') + } + res.set('Access-Control-Allow-Origin', `${protocol}//${host}`) if (headers) { diff --git a/package.json b/package.json index 08df735..00514e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gm5/core", - "version": "1.0.1", + "version": "1.0.2", "type": "module", "description": "Five.js, 一个轻量级的nodejs mvc框架 旨在简单易用, 5分钟即可上手", "author": "yutent ",