提交 8a0b9699 authored 作者: GOD_ZYX's avatar GOD_ZYX

sesssion 设置

上级 c1e3d913
...@@ -143,12 +143,6 @@ const agentProcessor = () => { ...@@ -143,12 +143,6 @@ const agentProcessor = () => {
if (_stoken) { if (_stoken) {
headers['stoken'] = _stoken headers['stoken'] = _stoken
} }
if (global.stoken) {
headers['stoken'] = global.stoken
let opts = { path: '/', domain: '.ezijing.com', expires: null, httpOnly: true }
res.cookie('_stoken', global.stoken, opts)
global.stoken = 0
}
/* 重新转发请求 */ /* 重新转发请求 */
axios(options).then((data) => { axios(options).then((data) => {
......
const express = require('express') const express = require('express')
const session = require('express-session') // const session = require('express-session')
const history = require('connect-history-api-fallback') const history = require('connect-history-api-fallback')
const path = require('path') const path = require('path')
const app = express() const app = express()
let sessionOpts = { // let sessionOpts = {
// 设置密钥 // // 设置密钥
secret: 'a cool secret', // secret: 'a cool secret',
// Forces the session to be saved back to the session store // // Forces the session to be saved back to the session store
resave: true, // resave: true,
// Forces a session that is "uninitialized" to be saved to the store. // // Forces a session that is "uninitialized" to be saved to the store.
saveUninitialized: true, // saveUninitialized: true,
// 设置会话cookie名, 默认是connect.sid // // 设置会话cookie名, 默认是connect.sid
key: '_STOKEN', // key: '_STOKEN',
// If secure is set to true, and you access your site over HTTP, the cookie will not be set. // // If secure is set to true, and you access your site over HTTP, the cookie will not be set.
cookie: { maxAge: 1000 * 60 * 60 * 2, secure: false } // cookie: { maxAge: 1000 * 60 * 60 * 2, secure: false }
} // }
app.set('port', process.env.SERVER_PORT || 3000) app.set('port', process.env.SERVER_PORT || 3000)
...@@ -28,7 +28,8 @@ app.get('/', (req, res) => { ...@@ -28,7 +28,8 @@ app.get('/', (req, res) => {
/* 增加 限定条件,如果是 e-learning2 子域名,那么 referer 为指定 域名 否则不能打开 */ /* 增加 限定条件,如果是 e-learning2 子域名,那么 referer 为指定 域名 否则不能打开 */
if (/^e-learning2\./.test(req.headers.host)) { if (/^e-learning2\./.test(req.headers.host)) {
if (/(sofia\.tenant\.ezijing)|(sofia-x\.ezijing)|(course\.ezijing)|(course3\.ezijing)/.test(req.headers.referer)) { if (/(sofia\.tenant\.ezijing)|(sofia-x\.ezijing)|(course\.ezijing)|(course3\.ezijing)/.test(req.headers.referer)) {
req.session._stoken = req.query.stoken || 0 let opts = { path: '/', domain: '.ezijing.com', expires: null, httpOnly: true }
res.cookie('_stoken', req.query.stoken, opts)
res.sendFile(path.join(__dirname, '../client-dist/index.html')) res.sendFile(path.join(__dirname, '../client-dist/index.html'))
} else { } else {
res.send('当前页面打开方式不对') res.send('当前页面打开方式不对')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论