Skip to content

Commit

Permalink
🎨 replace config.getSocket()
Browse files Browse the repository at this point in the history
refs #6982
- was a function in ConfigManager
- does belong to the GhostServer logic

[ci skip]
  • Loading branch information
kirrg001 authored and ErisDS committed Sep 20, 2016
1 parent f4bee50 commit d42f4f6
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions core/server/ghost-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
var Promise = require('bluebird'),
chalk = require('chalk'),
fs = require('fs'),
path = require('path'),
_ = require('lodash'),
errors = require('./errors'),
config = require('./config'),
i18n = require('./i18n'),
Expand Down Expand Up @@ -35,22 +37,33 @@ function GhostServer(rootApp) {
*/
GhostServer.prototype.start = function (externalApp) {
var self = this,
rootApp = externalApp ? externalApp : self.rootApp;
rootApp = externalApp ? externalApp : self.rootApp,
socketConfig, socketValues = {
path: path.join(config.get('paths').contentPath, process.env.NODE_ENV + '.socket'),
permissions: '660'
};

return new Promise(function (resolve) {
var socketConfig = config.getSocket();
if (config.get('server').hasOwnProperty('socket')) {
socketConfig = config.get('server').socket;

if (_.isString(socketConfig)) {
socketValues.path = socketConfig;
} else if (_.isObject(socketConfig)) {
socketValues.path = socketConfig.path || socketValues.path;
socketValues.permissions = socketConfig.permissions || socketValues.permissions;
}

if (socketConfig) {
// Make sure the socket is gone before trying to create another
try {
fs.unlinkSync(socketConfig.path);
fs.unlinkSync(socketValues.path);
} catch (e) {
// We can ignore this.
}

self.httpServer = rootApp.listen(socketConfig.path);

fs.chmod(socketConfig.path, socketConfig.permissions);
self.httpServer = rootApp.listen(socketValues.path);
fs.chmod(socketValues.path, socketValues.permissions);
config.set('server:socket', socketValues);
} else {
self.httpServer = rootApp.listen(
config.get('server').port,
Expand Down Expand Up @@ -176,7 +189,7 @@ GhostServer.prototype.logStartMessages = function () {
console.log(
chalk.green(i18n.t('notices.httpServer.ghostIsRunningIn', {env: process.env.NODE_ENV})),
i18n.t('notices.httpServer.listeningOn'),
config.getSocket() || config.get('server').host + ':' + config.get('server').port,
config.get('server').socket || config.get('server').host + ':' + config.get('server').port,
i18n.t('notices.httpServer.urlConfiguredAs', {url: config.get('url')}),
chalk.gray(i18n.t('notices.httpServer.ctrlCToShutDown'))
);
Expand Down

0 comments on commit d42f4f6

Please sign in to comment.