优化跨域配置;更新文档

v1 1.0.2
宇天 2020-09-30 14:25:08 +08:00
parent 36d28679e8
commit 70a2df5583
5 changed files with 19 additions and 7 deletions

View File

@ -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`, 然后根据提示操作, 即可

View File

@ -49,7 +49,7 @@ export default {
enabled: false,
credentials: false,
origin: [], // ['abc.com', 'a.foo.com']
maxAge: 0
maxAge: 14400
},
regexp: {
// 常用正则

View File

@ -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 })
// 安装模板引擎

View File

@ -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) {

View File

@ -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 <yutent.io@gmail.com>",