Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addresses an issue that cannot create session files on a read-only file system (#319, #320, #347) #348

Merged
merged 2 commits into from Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/api/api.commands.js
Expand Up @@ -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)
});
}
};
Expand Down Expand Up @@ -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)
});
}
};
Expand All @@ -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)
});
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/app/api/api.events.js
Expand Up @@ -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)
});
}
};
Expand Down Expand Up @@ -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)
});
}
};
Expand All @@ -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)
});
}
};
6 changes: 3 additions & 3 deletions src/app/api/api.macros.js
Expand Up @@ -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)
});
}
};
Expand Down Expand Up @@ -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)
});
}
};
Expand All @@ -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)
});
}
};
6 changes: 3 additions & 3 deletions src/app/api/api.users.js
Expand Up @@ -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)
});
}
};
Expand Down Expand Up @@ -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)
});
}
};
Expand All @@ -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)
});
}
};
17 changes: 13 additions & 4 deletions src/app/app.js
Expand Up @@ -124,24 +124,33 @@ 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) => {
log.debug.apply(log, args);
}
})
}));
} catch (err) {
log.error(err);
}

app.use(favicon(path.join(settings.assets.web.path, 'favicon.ico')));
Expand Down
11 changes: 4 additions & 7 deletions src/app/config/settings.base.js
Expand Up @@ -2,16 +2,16 @@ 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;

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,

Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/app/index.js
Expand Up @@ -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')) {
Expand Down