Browse Source

Use file to store session

master
Menci 8 years ago
parent
commit
92e7cc7c99
  1. 1
      .gitignore
  2. 11
      app.js
  3. 1
      package.json

1
.gitignore vendored

@ -1,3 +1,4 @@
sessions
config.json config.json
yarn.lock yarn.lock
*.db *.db

11
app.js

@ -34,6 +34,8 @@ global.syzoj = {
let Express = require('express'); let Express = require('express');
global.app = Express(); global.app = Express();
syzoj.production = app.get('env') === 'production';
app.listen(parseInt(syzoj.config.port), syzoj.config.hostname, () => { app.listen(parseInt(syzoj.config.port), syzoj.config.hostname, () => {
this.log(`SYZOJ is listening on ${syzoj.config.hostname}:${parseInt(syzoj.config.port)}...`); this.log(`SYZOJ is listening on ${syzoj.config.hostname}:${parseInt(syzoj.config.port)}...`);
}); });
@ -66,7 +68,8 @@ global.syzoj = {
this.db = new Sequelize(this.config.db.database, this.config.db.username, this.config.db.password, { this.db = new Sequelize(this.config.db.database, this.config.db.username, this.config.db.password, {
host: this.config.db.host, host: this.config.db.host,
dialect: this.config.db.dialect, dialect: this.config.db.dialect,
storage: this.config.db.storage ? this.utils.resolvePath(this.config.db.storage) : null storage: this.config.db.storage ? this.utils.resolvePath(this.config.db.storage) : null,
logging: syzoj.production ? false : syzoj.log
}); });
global.Promise = Sequelize.Promise; global.Promise = Sequelize.Promise;
this.db.sync(); this.db.sync();
@ -87,14 +90,16 @@ global.syzoj = {
}, },
loadHooks() { loadHooks() {
let Session = require('express-session'); let Session = require('express-session');
let FileStore = require('session-file-store')(Session);
let sessionConfig = { let sessionConfig = {
secret: this.config.session_secret, secret: this.config.session_secret,
cookie: {}, cookie: {},
rolling: true, rolling: true,
saveUninitialized: true, saveUninitialized: true,
resave: true resave: true,
store: new FileStore
}; };
if (app.get('env') === 'production') { if (syzoj.production) {
app.set('trust proxy', 1); app.set('trust proxy', 1);
sessionConfig.cookie.secure = true; sessionConfig.cookie.secure = true;
} }

1
package.json

@ -39,6 +39,7 @@
"mysql": "^2.11.1", "mysql": "^2.11.1",
"request": "^2.74.0", "request": "^2.74.0",
"sequelize": "^3.24.3", "sequelize": "^3.24.3",
"session-file-store": "^1.0.0",
"sqlite3": "^3.1.4", "sqlite3": "^3.1.4",
"syzoj-divine": "^1.0.0" "syzoj-divine": "^1.0.0"
} }

Loading…
Cancel
Save