From 7ec4e2ea20d9ec776b0071c25d1e81a9d75eb1eb Mon Sep 17 00:00:00 2001 From: Cheton Wu Date: Thu, 5 Jul 2018 15:49:56 +0800 Subject: [PATCH 1/2] Rename cncrc to rcfile --- src/app/api/api.commands.js | 6 +++--- src/app/api/api.events.js | 6 +++--- src/app/api/api.macros.js | 6 +++--- src/app/api/api.users.js | 6 +++--- src/app/index.js | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/app/api/api.commands.js b/src/app/api/api.commands.js index a4a1de078..2ef323d63 100644 --- a/src/app/api/api.commands.js +++ b/src/app/api/api.commands.js @@ -122,7 +122,7 @@ export const create = (req, res) => { res.send({ id: record.id, mtime: record.mtime }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; @@ -179,7 +179,7 @@ export const update = (req, res) => { res.send({ id: record.id, mtime: record.mtime }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; @@ -205,7 +205,7 @@ export const __delete = (req, res) => { res.send({ id: record.id }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; diff --git a/src/app/api/api.events.js b/src/app/api/api.events.js index dd3710c63..070f3ff7c 100644 --- a/src/app/api/api.events.js +++ b/src/app/api/api.events.js @@ -130,7 +130,7 @@ export const create = (req, res) => { res.send({ id: record.id, mtime: record.mtime }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; @@ -189,7 +189,7 @@ export const update = (req, res) => { res.send({ id: record.id, mtime: record.mtime }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; @@ -215,7 +215,7 @@ export const __delete = (req, res) => { res.send({ id: record.id }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; diff --git a/src/app/api/api.macros.js b/src/app/api/api.macros.js index 4261793d1..bbcdc7239 100644 --- a/src/app/api/api.macros.js +++ b/src/app/api/api.macros.js @@ -105,7 +105,7 @@ export const create = (req, res) => { res.send({ err: null }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; @@ -169,7 +169,7 @@ export const update = (req, res) => { res.send({ err: null }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; @@ -195,7 +195,7 @@ export const __delete = (req, res) => { res.send({ err: null }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; diff --git a/src/app/api/api.users.js b/src/app/api/api.users.js index 84c75a276..f20a5315b 100644 --- a/src/app/api/api.users.js +++ b/src/app/api/api.users.js @@ -213,7 +213,7 @@ export const create = (req, res) => { res.send({ id: record.id, mtime: record.mtime }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; @@ -289,7 +289,7 @@ export const update = (req, res) => { res.send({ id: record.id, mtime: record.mtime }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; @@ -315,7 +315,7 @@ export const __delete = (req, res) => { res.send({ id: record.id }); } catch (err) { res.status(ERR_INTERNAL_SERVER_ERROR).send({ - msg: 'Failed to save ' + JSON.stringify(settings.cncrc) + msg: 'Failed to save ' + JSON.stringify(settings.rcfile) }); } }; diff --git a/src/app/index.js b/src/app/index.js index 84c602b53..eccaa52b8 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -45,14 +45,14 @@ const createServer = (options, callback) => { } } - const cncrc = path.resolve(options.configFile || settings.cncrc); + const rcfile = path.resolve(options.configFile || settings.rcfile); // configstore service - log.info(`Loading configuration from ${chalk.yellow(JSON.stringify(cncrc))}`); - config.load(cncrc); + log.info(`Loading configuration from ${chalk.yellow(JSON.stringify(rcfile))}`); + config.load(rcfile); - // cncrc - settings.cncrc = cncrc; + // rcfile + settings.rcfile = rcfile; { // secret if (!config.get('secret')) { From 8ce2b79ed3f5c74d79bb9498a919c03e02faf980 Mon Sep 17 00:00:00 2001 From: Cheton Wu Date: Thu, 5 Jul 2018 16:00:01 +0800 Subject: [PATCH 2/2] Create session file path under user's home directory (#319, #320, #347) --- src/app/app.js | 17 +++++++++++++---- src/app/config/settings.base.js | 11 ++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/app/app.js b/src/app/app.js index 93e2bd867..5dbde2f15 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -124,17 +124,24 @@ const appMain = () => { // Middleware // https://github.com/senchalabs/connect - { // https://github.com/valery-barysok/session-file-store - const path = './sessions'; + try { + // https://github.com/valery-barysok/session-file-store + const path = settings.middleware.session.path; // Defaults to './cncjs-sessions' rimraf.sync(path); - fs.mkdirSync(path); // Defaults to ./sessions + fs.mkdirSync(path); const FileStore = sessionFileStore(session); app.use(session({ - ...settings.middleware.session, // https://github.com/expressjs/session#secret secret: settings.secret, + + // https://github.com/expressjs/session#resave + resave: true, + + // https://github.com/expressjs/session#saveuninitialized + saveUninitialized: true, + store: new FileStore({ path: path, logFn: (...args) => { @@ -142,6 +149,8 @@ const appMain = () => { } }) })); + } catch (err) { + log.error(err); } app.use(favicon(path.join(settings.assets.web.path, 'favicon.ico'))); diff --git a/src/app/config/settings.base.js b/src/app/config/settings.base.js index c4694af16..5c11b3185 100644 --- a/src/app/config/settings.base.js +++ b/src/app/config/settings.base.js @@ -2,8 +2,8 @@ import path from 'path'; import pkg from '../../package.json'; import { languages } from '../../../build.config'; -// RCFile -const RCFILE = '.cncrc'; +const RC_FILE = '.cncrc'; +const SESSION_PATH = '.cncjs-sessions'; // Secret const secret = pkg.version; @@ -11,7 +11,7 @@ const secret = pkg.version; const getUserHome = () => (process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']); export default { - cncrc: path.resolve(getUserHome(), RCFILE), + rcfile: path.resolve(getUserHome(), RC_FILE), verbosity: 0, version: pkg.version, @@ -90,10 +90,7 @@ export default { }, // https://github.com/expressjs/session 'session': { - // https://github.com/expressjs/session#resave - resave: true, - // https://github.com/expressjs/session#saveuninitialized - saveUninitialized: true + path: path.resolve(getUserHome(), SESSION_PATH) } }, siofu: { // SocketIOFileUploader