2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Allow socket permissions to be set from config

Closes #4478
This commit is contained in:
Jason Williams 2014-12-31 15:23:46 +00:00
parent 4f278e3cf7
commit 6c1287c3a2
3 changed files with 54 additions and 12 deletions

View file

@ -41,11 +41,29 @@ function ConfigManager(config) {
// Are we using sockets? Custom socket or the default?
ConfigManager.prototype.getSocket = function () {
var socketConfig,
values = {
path: path.join(this._config.paths.contentPath, process.env.NODE_ENV + '.socket'),
permissions: '660'
};
if (this._config.server.hasOwnProperty('socket')) {
return _.isString(this._config.server.socket) ?
this._config.server.socket :
path.join(this._config.paths.contentPath, process.env.NODE_ENV + '.socket');
socketConfig = this._config.server.socket;
if (_.isString(socketConfig)) {
values.path = socketConfig;
return values;
}
if (_.isObject(socketConfig)) {
values.path = socketConfig.path || values.path;
values.permissions = socketConfig.permissions || values.permissions;
return values;
}
}
return false;
};

View file

@ -124,19 +124,19 @@ GhostServer.prototype.start = function (externalApp) {
// ## Start Ghost App
return new Promise(function (resolve) {
if (config.getSocket()) {
var socketConfig = config.getSocket();
if (socketConfig) {
// Make sure the socket is gone before trying to create another
try {
fs.unlinkSync(config.getSocket());
fs.unlinkSync(socketConfig.path);
} catch (e) {
// We can ignore this.
}
self.httpServer = rootApp.listen(
config.getSocket()
);
self.httpServer = rootApp.listen(socketConfig.path);
fs.chmod(config.getSocket(), '0660');
fs.chmod(socketConfig.path, socketConfig.permissions);
} else {
self.httpServer = rootApp.listen(
config.server.port,

View file

@ -519,9 +519,33 @@ describe('Config', function () {
it('allows server to use a socket', function (done) {
overrideConfig({server: {socket: 'test'}});
config.load().then(function (localConfig) {
should.exist(localConfig);
localConfig.server.socket.should.equal('test');
config.load().then(function () {
var socketConfig = config.getSocket();
socketConfig.should.be.an.Object;
socketConfig.path.should.equal('test');
socketConfig.permissions.should.equal('660');
done();
}).catch(done);
});
it('allows server to use a socket and user-defined permissions', function (done) {
overrideConfig({
server: {
socket: {
path: 'test',
permissions: '666'
}
}
});
config.load().then(function () {
var socketConfig = config.getSocket();
socketConfig.should.be.an.Object;
socketConfig.path.should.equal('test');
socketConfig.permissions.should.equal('666');
done();
}).catch(done);