diff --git a/Readme.md b/Readme.md index 9e8872d..da49202 100644 --- a/Readme.md +++ b/Readme.md @@ -65,16 +65,19 @@ 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({ VIEWS: './views/' }) // [可选], 但是要用到模板渲染页面时, 必须指定 +// 设置域,cookie用到,不设置则等同于website +// app.set({ domain: 'your_domain.com' }) + +// [可选], 但是要用到模板渲染页面时, 必须指定 +// app.set({ views: { enabled: true, dir: './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 a69f5e6..0732211 100644 --- a/config/index.js +++ b/config/index.js @@ -40,7 +40,7 @@ export default { passwd: '' }, views: { - enabled: true, + enabled: false, dir: '', ext: '.htm' }, @@ -48,7 +48,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 6e41bda..43235b7 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,7 @@ /** * 框架核心 - * @authors yutent (yutent@doui.cc) - * @date 2015-11-25 18:06:14 - * + * @author yutent + * @date 2020/09/28 10:01:47 */ import 'es.shim' // 加载拓展方法 @@ -39,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 }) // 安装模板引擎 @@ -125,6 +126,7 @@ export default class Five { } this.__MODULES__[name] = import(item).catch(err => { + console.error(err) return { default: null } }) }) 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 d9d6547..4a3ff86 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "author": "yutent ", "main": "index.js", "dependencies": { - "@gm5/session": "^1.1.0", - "@gm5/request": "^1.2.1", + "@gm5/session": "^1.1.1", + "@gm5/request": "^1.2.3", "@gm5/response": "^1.3.1", "@gm5/controller": "^1.0.0", "@gm5/jwt": "^1.1.0",