Naming cleanup

closes #4069
- Rename everything from camelCase to lowercase + dashes
- Remove usage of `server`, `app` and `instance`
This commit is contained in:
Fabian Becker 2014-09-19 16:17:58 +00:00
parent a3093b9b42
commit 2c3abeee03
40 changed files with 122 additions and 155 deletions

View File

@ -4,16 +4,16 @@ var _ = require('lodash'),
path = require('path'), path = require('path'),
Promise = require('bluebird'), Promise = require('bluebird'),
hbs = require('express-hbs'), hbs = require('express-hbs'),
NotFoundError = require('./notfounderror'), NotFoundError = require('./not-found-error'),
BadRequestError = require('./badrequesterror'), BadRequestError = require('./bad-request-error'),
InternalServerError = require('./internalservererror'), InternalServerError = require('./internal-server-error'),
NoPermissionError = require('./nopermissionerror'), NoPermissionError = require('./no-permission-error'),
RequestEntityTooLargeError = require('./requesttoolargeerror'), RequestEntityTooLargeError = require('./request-too-large-error'),
UnauthorizedError = require('./unauthorizederror'), UnauthorizedError = require('./unauthorized-error'),
ValidationError = require('./validationerror'), ValidationError = require('./validation-error'),
UnsupportedMediaTypeError = require('./unsupportedmediaerror'), UnsupportedMediaTypeError = require('./unsupported-media-type-error'),
EmailError = require('./emailerror'), EmailError = require('./email-error'),
DataImportError = require('./dataimporterror'), DataImportError = require('./data-import-error'),
config, config,
errors, errors,

View File

@ -4,8 +4,8 @@ var Promise = require('bluebird'),
packageInfo = require('../../package.json'), packageInfo = require('../../package.json'),
config = require('./config'); config = require('./config');
function GhostServer(app) { function GhostServer(rootApp) {
this.app = app; this.rootApp = rootApp;
this.httpServer = null; this.httpServer = null;
this.connections = []; this.connections = [];
this.upgradeWarning = setTimeout(this.logUpgradeWarning.bind(this), 5000); this.upgradeWarning = setTimeout(this.logUpgradeWarning.bind(this), 5000);
@ -98,7 +98,7 @@ GhostServer.prototype.logUpgradeWarning = function () {
*/ */
GhostServer.prototype.start = function (externalApp) { GhostServer.prototype.start = function (externalApp) {
var self = this, var self = this,
app = externalApp ? externalApp : self.app; rootApp = externalApp ? externalApp : self.rootApp;
// ## Start Ghost App // ## Start Ghost App
return new Promise(function (resolve) { return new Promise(function (resolve) {
@ -110,13 +110,13 @@ GhostServer.prototype.start = function (externalApp) {
// We can ignore this. // We can ignore this.
} }
self.httpServer = app.listen( self.httpServer = rootApp.listen(
config.getSocket() config.getSocket()
); );
fs.chmod(config.getSocket(), '0660'); fs.chmod(config.getSocket(), '0660');
} else { } else {
self.httpServer = app.listen( self.httpServer = rootApp.listen(
config.server.port, config.server.port,
config.server.host config.server.host
); );

View File

@ -19,7 +19,7 @@ var crypto = require('crypto'),
permissions = require('./permissions'), permissions = require('./permissions'),
apps = require('./apps'), apps = require('./apps'),
packageInfo = require('../../package.json'), packageInfo = require('../../package.json'),
GhostServer = require('./GhostServer'), GhostServer = require('./ghost-server'),
// Variables // Variables
dbHash; dbHash;
@ -131,8 +131,8 @@ function initNotifications() {
// Finally it returns an instance of GhostServer // Finally it returns an instance of GhostServer
function init(options) { function init(options) {
// Get reference to an express app instance. // Get reference to an express app instance.
var server = options.app ? options.app : express(), var blogApp = express(),
adminExpress = express(), adminApp = express(),
// create a hash for cache busting assets // create a hash for cache busting assets
assetHash = (crypto.createHash('md5').update(packageInfo.version + Date.now()).digest('hex')).substring(0, 10); assetHash = (crypto.createHash('md5').update(packageInfo.version + Date.now()).digest('hex')).substring(0, 10);
@ -184,22 +184,22 @@ function init(options) {
// enabled gzip compression by default // enabled gzip compression by default
if (config.server.compress !== false) { if (config.server.compress !== false) {
server.use(compress()); blogApp.use(compress());
} }
// ## View engine // ## View engine
// set the view engine // set the view engine
server.set('view engine', 'hbs'); blogApp.set('view engine', 'hbs');
// Create a hbs instance for admin and init view engine // Create a hbs instance for admin and init view engine
adminExpress.set('view engine', 'hbs'); adminApp.set('view engine', 'hbs');
adminExpress.engine('hbs', adminHbs.express3({})); adminApp.engine('hbs', adminHbs.express3({}));
// Load helpers // Load helpers
helpers.loadCoreHelpers(adminHbs, assetHash); helpers.loadCoreHelpers(adminHbs, assetHash);
// ## Middleware and Routing // ## Middleware and Routing
middleware(server, adminExpress); middleware(blogApp, adminApp);
// Log all theme errors and warnings // Log all theme errors and warnings
_.each(config.paths.availableThemes._messages.errors, function (error) { _.each(config.paths.availableThemes._messages.errors, function (error) {
@ -210,7 +210,7 @@ function init(options) {
errors.logWarn(warn.message, warn.context, warn.help); errors.logWarn(warn.message, warn.context, warn.help);
}); });
return new GhostServer(server); return new GhostServer(blogApp);
}); });
} }

View File

@ -22,10 +22,10 @@ var api = require('../api'),
passport = require('passport'), passport = require('passport'),
oauth = require('./oauth'), oauth = require('./oauth'),
oauth2orize = require('oauth2orize'), oauth2orize = require('oauth2orize'),
authStrategies = require('./authStrategies'), authStrategies = require('./auth-strategies'),
utils = require('../utils'), utils = require('../utils'),
expressServer, blogApp,
setupMiddleware; setupMiddleware;
// ##Custom Middleware // ##Custom Middleware
@ -50,7 +50,7 @@ function activateTheme(activeTheme) {
themePartials = path.join(config.paths.themePath, activeTheme, 'partials'); themePartials = path.join(config.paths.themePath, activeTheme, 'partials');
// clear the view cache // clear the view cache
expressServer.cache = {}; blogApp.cache = {};
// set view engine // set view engine
hbsOptions = {partialsDir: [config.paths.helperTemplates]}; hbsOptions = {partialsDir: [config.paths.helperTemplates]};
@ -62,13 +62,13 @@ function activateTheme(activeTheme) {
} }
}); });
expressServer.engine('hbs', hbs.express3(hbsOptions)); blogApp.engine('hbs', hbs.express3(hbsOptions));
// Update user error template // Update user error template
errors.updateActiveTheme(activeTheme); errors.updateActiveTheme(activeTheme);
// Set active theme variable on the express server // Set active theme variable on the express server
expressServer.set('activeTheme', activeTheme); blogApp.set('activeTheme', activeTheme);
} }
// ### decideIsAdmin Middleware // ### decideIsAdmin Middleware
// Uses the URL to detect whether this response should be an admin response // Uses the URL to detect whether this response should be an admin response
@ -89,7 +89,7 @@ function configHbsForContext(req, res, next) {
} }
hbs.updateTemplateOptions({data: {blog: themeData}}); hbs.updateTemplateOptions({data: {blog: themeData}});
expressServer.set('views', path.join(config.paths.themePath, expressServer.get('activeTheme'))); blogApp.set('views', path.join(config.paths.themePath, blogApp.get('activeTheme')));
// Pass 'secure' flag to the view engine // Pass 'secure' flag to the view engine
// so that templates can choose 'url' vs 'urlSSL' // so that templates can choose 'url' vs 'urlSSL'
@ -99,14 +99,14 @@ function configHbsForContext(req, res, next) {
} }
// ### updateActiveTheme // ### updateActiveTheme
// Updates the expressServer's activeTheme variable and subsequently // Updates the blogApp's activeTheme variable and subsequently
// activates that theme's views with the hbs templating engine if it // activates that theme's views with the hbs templating engine if it
// is not yet activated. // is not yet activated.
function updateActiveTheme(req, res, next) { function updateActiveTheme(req, res, next) {
api.settings.read({context: {internal: true}, key: 'activeTheme'}).then(function (response) { api.settings.read({context: {internal: true}, key: 'activeTheme'}).then(function (response) {
var activeTheme = response.settings[0]; var activeTheme = response.settings[0];
// Check if the theme changed // Check if the theme changed
if (activeTheme.value !== expressServer.get('activeTheme')) { if (activeTheme.value !== blogApp.get('activeTheme')) {
// Change theme // Change theme
if (!config.paths.availableThemes.hasOwnProperty(activeTheme.value)) { if (!config.paths.availableThemes.hasOwnProperty(activeTheme.value)) {
if (!res.isAdmin) { if (!res.isAdmin) {
@ -121,7 +121,7 @@ function updateActiveTheme(req, res, next) {
}).catch(function (err) { }).catch(function (err) {
// Trying to start up without the active theme present, setup a simple hbs instance // Trying to start up without the active theme present, setup a simple hbs instance
// and render an error page straight away. // and render an error page straight away.
expressServer.engine('hbs', hbs.express3()); blogApp.engine('hbs', hbs.express3());
next(err); next(err);
}); });
} }
@ -235,7 +235,7 @@ function serveSharedFile(file, type, maxAge) {
}; };
} }
setupMiddleware = function (server, adminExpress) { setupMiddleware = function (blogAppInstance, adminApp) {
var logging = config.logging, var logging = config.logging,
corePath = config.paths.corePath, corePath = config.paths.corePath,
oauthServer = oauth2orize.createServer(); oauthServer = oauth2orize.createServer();
@ -244,98 +244,98 @@ setupMiddleware = function (server, adminExpress) {
authStrategies = authStrategies; authStrategies = authStrategies;
// Cache express server instance // Cache express server instance
expressServer = server; blogApp = blogAppInstance;
middleware.cacheServer(expressServer); middleware.cacheBlogApp(blogApp);
middleware.cacheOauthServer(oauthServer); middleware.cacheOauthServer(oauthServer);
oauth.init(oauthServer, middleware.resetSpamCounter); oauth.init(oauthServer, middleware.resetSpamCounter);
// Make sure 'req.secure' is valid for proxied requests // Make sure 'req.secure' is valid for proxied requests
// (X-Forwarded-Proto header will be checked, if present) // (X-Forwarded-Proto header will be checked, if present)
expressServer.enable('trust proxy'); blogApp.enable('trust proxy');
// Logging configuration // Logging configuration
if (logging !== false) { if (logging !== false) {
if (expressServer.get('env') !== 'development') { if (blogApp.get('env') !== 'development') {
expressServer.use(logger('combined', logging)); blogApp.use(logger('combined', logging));
} else { } else {
expressServer.use(logger('dev', logging)); blogApp.use(logger('dev', logging));
} }
} }
// Favicon // Favicon
expressServer.use(serveSharedFile('favicon.ico', 'image/x-icon', utils.ONE_DAY_S)); blogApp.use(serveSharedFile('favicon.ico', 'image/x-icon', utils.ONE_DAY_S));
// Static assets // Static assets
expressServer.use('/shared', express['static'](path.join(corePath, '/shared'), {maxAge: utils.ONE_HOUR_MS})); blogApp.use('/shared', express['static'](path.join(corePath, '/shared'), {maxAge: utils.ONE_HOUR_MS}));
expressServer.use('/content/images', storage.getStorage().serve()); blogApp.use('/content/images', storage.getStorage().serve());
expressServer.use('/ghost/scripts', express['static'](path.join(corePath, '/built/scripts'), {maxAge: utils.ONE_YEAR_MS})); blogApp.use('/ghost/scripts', express['static'](path.join(corePath, '/built/scripts'), {maxAge: utils.ONE_YEAR_MS}));
expressServer.use('/public', express['static'](path.join(corePath, '/built/public'), {maxAge: utils.ONE_YEAR_MS})); blogApp.use('/public', express['static'](path.join(corePath, '/built/public'), {maxAge: utils.ONE_YEAR_MS}));
// First determine whether we're serving admin or theme content // First determine whether we're serving admin or theme content
expressServer.use(decideIsAdmin); blogApp.use(decideIsAdmin);
expressServer.use(updateActiveTheme); blogApp.use(updateActiveTheme);
expressServer.use(configHbsForContext); blogApp.use(configHbsForContext);
// Admin only config // Admin only config
expressServer.use('/ghost', express['static'](path.join(corePath, '/client/assets'), {maxAge: utils.ONE_YEAR_MS})); blogApp.use('/ghost', express['static'](path.join(corePath, '/client/assets'), {maxAge: utils.ONE_YEAR_MS}));
// Force SSL // Force SSL
// NOTE: Importantly this is _after_ the check above for admin-theme static resources, // NOTE: Importantly this is _after_ the check above for admin-theme static resources,
// which do not need HTTPS. In fact, if HTTPS is forced on them, then 404 page might // which do not need HTTPS. In fact, if HTTPS is forced on them, then 404 page might
// not display properly when HTTPS is not available! // not display properly when HTTPS is not available!
expressServer.use(checkSSL); blogApp.use(checkSSL);
adminExpress.set('views', config.paths.adminViews); adminApp.set('views', config.paths.adminViews);
// Theme only config // Theme only config
expressServer.use(middleware.staticTheme()); blogApp.use(middleware.staticTheme());
// Serve robots.txt if not found in theme // Serve robots.txt if not found in theme
expressServer.use(serveSharedFile('robots.txt', 'text/plain', utils.ONE_YEAR_S)); blogApp.use(serveSharedFile('robots.txt', 'text/plain', utils.ONE_YEAR_S));
// Add in all trailing slashes, properly include the subdir path // Add in all trailing slashes, properly include the subdir path
// in the redirect. // in the redirect.
expressServer.use(slashes(true, { blogApp.use(slashes(true, {
headers: { headers: {
'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S 'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S
}, },
base: config.paths.subdir base: config.paths.subdir
})); }));
expressServer.use(uncapitalise); blogApp.use(uncapitalise);
// Body parsing // Body parsing
expressServer.use(bodyParser.json()); blogApp.use(bodyParser.json());
expressServer.use(bodyParser.urlencoded({extended: true})); blogApp.use(bodyParser.urlencoded({extended: true}));
expressServer.use(passport.initialize()); blogApp.use(passport.initialize());
// ### Caching // ### Caching
expressServer.use(middleware.cacheControl('public')); blogApp.use(middleware.cacheControl('public'));
adminExpress.use(middleware.cacheControl('private')); adminApp.use(middleware.cacheControl('private'));
// enable authentication // enable authentication
expressServer.use(middleware.authenticate); blogApp.use(middleware.authenticate);
// local data // local data
expressServer.use(ghostLocals); blogApp.use(ghostLocals);
// ### Routing // ### Routing
// Set up API routes // Set up API routes
expressServer.use(routes.apiBaseUri, routes.api(middleware)); blogApp.use(routes.apiBaseUri, routes.api(middleware));
// Mount admin express app to /ghost and set up routes // Mount admin express app to /ghost and set up routes
adminExpress.use(middleware.redirectToSetup); adminApp.use(middleware.redirectToSetup);
adminExpress.use(routes.admin()); adminApp.use(routes.admin());
expressServer.use('/ghost', adminExpress); blogApp.use('/ghost', adminApp);
// Set up Frontend routes // Set up Frontend routes
expressServer.use(routes.frontend()); blogApp.use(routes.frontend());
// ### Error handling // ### Error handling
// 404 Handler // 404 Handler
expressServer.use(errors.error404); blogApp.use(errors.error404);
// 500 Handler // 500 Handler
expressServer.use(errors.error500); blogApp.use(errors.error500);
}; };
module.exports = setupMiddleware; module.exports = setupMiddleware;

View File

@ -13,7 +13,7 @@ var _ = require('lodash'),
utils = require('../utils'), utils = require('../utils'),
middleware, middleware,
expressServer, blogApp,
oauthServer, oauthServer,
loginSecurity = [], loginSecurity = [],
forgottenSecurity = []; forgottenSecurity = [];
@ -24,8 +24,8 @@ function isBlackListedFileType(file) {
return _.contains(blackListedFileTypes, ext); return _.contains(blackListedFileTypes, ext);
} }
function cacheServer(server) { function cacheBlogApp(app) {
expressServer = server; blogApp = app;
} }
function cacheOauthServer(server) { function cacheOauthServer(server) {
@ -105,7 +105,7 @@ middleware = {
whenEnabled: function (setting, fn) { whenEnabled: function (setting, fn) {
return function settingEnabled(req, res, next) { return function settingEnabled(req, res, next) {
// Set from server/middleware/index.js for now // Set from server/middleware/index.js for now
if (expressServer.enabled(setting)) { if (blogApp.enabled(setting)) {
fn(req, res, next); fn(req, res, next);
} else { } else {
next(); next();
@ -263,5 +263,5 @@ middleware = {
}; };
module.exports = middleware; module.exports = middleware;
module.exports.cacheServer = cacheServer; module.exports.cacheBlogApp = cacheBlogApp;
module.exports.cacheOauthServer = cacheOauthServer; module.exports.cacheOauthServer = cacheOauthServer;

View File

@ -282,13 +282,13 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
add: function (data, options) { add: function (data, options) {
data = this.filterData(data); data = this.filterData(data);
options = this.filterOptions(options, 'add'); options = this.filterOptions(options, 'add');
var instance = this.forge(data); var model = this.forge(data);
// We allow you to disable timestamps when importing posts so that the new posts `updated_at` value is the same // We allow you to disable timestamps when importing posts so that the new posts `updated_at` value is the same
// as the import json blob. More details refer to https://github.com/TryGhost/Ghost/issues/1696 // as the import json blob. More details refer to https://github.com/TryGhost/Ghost/issues/1696
if (options.importing) { if (options.importing) {
instance.hasTimestamps = false; model.hasTimestamps = false;
} }
return instance.save(null, options); return model.save(null, options);
}, },
/** /**

View File

@ -51,7 +51,7 @@ CanThisResult = function () {
CanThisResult.prototype.buildObjectTypeHandlers = function (objTypes, actType, context, permissionLoad) { CanThisResult.prototype.buildObjectTypeHandlers = function (objTypes, actType, context, permissionLoad) {
// @TODO: remove this lazy require // @TODO: remove this lazy require
var objectTypeModelMap = require('./objectTypeModelMap'); var objectTypeModelMap = require('./object-type-model-map');
// Iterate through the object types, i.e. ['post', 'tag', 'user'] // Iterate through the object types, i.e. ['post', 'tag', 'user']
return _.reduce(objTypes, function (objTypeHandlers, objType) { return _.reduce(objTypes, function (objTypeHandlers, objType) {

View File

@ -4,7 +4,7 @@ var errors = require('../errors'),
function getStorage(storageChoice) { function getStorage(storageChoice) {
// TODO: this is where the check for storage apps should go // TODO: this is where the check for storage apps should go
// Local file system is the default. Fow now that is all we support. // Local file system is the default. Fow now that is all we support.
storageChoice = 'localfilesystem'; storageChoice = 'local-file-store';
if (storage[storageChoice]) { if (storage[storageChoice]) {
return storage[storageChoice]; return storage[storageChoice];

View File

@ -6,7 +6,6 @@
// But then again testing real code, rather than mock code, might be more useful... // But then again testing real code, rather than mock code, might be more useful...
var request = require('supertest'), var request = require('supertest'),
express = require('express'),
should = require('should'), should = require('should'),
testUtils = require('../../utils'), testUtils = require('../../utils'),
@ -47,11 +46,9 @@ describe('Admin Routing', function () {
} }
before(function (done) { before(function (done) {
var app = express(); ghost().then(function (ghostServer) {
ghost({app: app}).then(function () {
// Setup the request object with the ghost express app // Setup the request object with the ghost express app
request = request(app); request = request(ghostServer.rootApp);
done(); done();
}).catch(function (e) { }).catch(function (e) {

View File

@ -1,7 +1,6 @@
/*global describe, it, before, after */ /*global describe, it, before, after */
/*jshint expr:true*/ /*jshint expr:true*/
var supertest = require('supertest'), var supertest = require('supertest'),
express = require('express'),
should = require('should'), should = require('should'),
testUtils = require('../../../utils'), testUtils = require('../../../utils'),
user = testUtils.DataGenerator.forModel.users[0], user = testUtils.DataGenerator.forModel.users[0],
@ -12,12 +11,10 @@ describe('Authentication API', function () {
var accesstoken = ''; var accesstoken = '';
before(function (done) { before(function (done) {
var app = express();
// starting ghost automatically populates the db // starting ghost automatically populates the db
// TODO: prevent db init, and manage bringing up the DB with fixtures ourselves // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves
ghost({app: app}).then(function () { ghost().then(function (ghostServer) {
request = supertest.agent(app); request = supertest.agent(ghostServer.rootApp);
}).then(function () { }).then(function () {
return testUtils.doAuth(request); return testUtils.doAuth(request);
}).then(function (token) { }).then(function (token) {

View File

@ -1,7 +1,6 @@
/*global describe, it, before, after */ /*global describe, it, before, after */
/*jshint expr:true*/ /*jshint expr:true*/
var supertest = require('supertest'), var supertest = require('supertest'),
express = require('express'),
should = require('should'), should = require('should'),
testUtils = require('../../../utils'), testUtils = require('../../../utils'),
ghost = require('../../../../../core'), ghost = require('../../../../../core'),
@ -11,12 +10,10 @@ describe('DB API', function () {
var accesstoken = ''; var accesstoken = '';
before(function (done) { before(function (done) {
var app = express();
// starting ghost automatically populates the db // starting ghost automatically populates the db
// TODO: prevent db init, and manage bringing up the DB with fixtures ourselves // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves
ghost({app: app}).then(function () { ghost().then(function (ghostServer) {
request = supertest.agent(app); request = supertest.agent(ghostServer.rootApp);
}).then(function () { }).then(function () {
return testUtils.doAuth(request); return testUtils.doAuth(request);
}).then(function (token) { }).then(function (token) {

View File

@ -6,7 +6,6 @@
// But then again testing real code, rather than mock code, might be more useful... // But then again testing real code, rather than mock code, might be more useful...
var supertest = require('supertest'), var supertest = require('supertest'),
express = require('express'),
should = require('should'), should = require('should'),
testUtils = require('../../../utils'), testUtils = require('../../../utils'),
@ -15,10 +14,8 @@ var supertest = require('supertest'),
describe('Unauthorized', function () { describe('Unauthorized', function () {
before(function (done) { before(function (done) {
var app = express(); ghost().then(function (ghostServer) {
request = supertest.agent(ghostServer.rootApp);
ghost({app: app}).then(function () {
request = supertest.agent(app);
done(); done();
}); });

View File

@ -2,7 +2,6 @@
/*jshint expr:true*/ /*jshint expr:true*/
var testUtils = require('../../../utils'), var testUtils = require('../../../utils'),
supertest = require('supertest'), supertest = require('supertest'),
express = require('express'),
ghost = require('../../../../../core'), ghost = require('../../../../../core'),
@ -12,12 +11,10 @@ describe('Notifications API', function () {
var accesstoken = ''; var accesstoken = '';
before(function (done) { before(function (done) {
var app = express();
// starting ghost automatically populates the db // starting ghost automatically populates the db
// TODO: prevent db init, and manage bringing up the DB with fixtures ourselves // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves
ghost({app: app}).then(function () { ghost().then(function (ghostServer) {
request = supertest.agent(app); request = supertest.agent(ghostServer.rootApp);
}).then(function () { }).then(function () {
return testUtils.doAuth(request); return testUtils.doAuth(request);
}).then(function (token) { }).then(function (token) {

View File

@ -3,7 +3,6 @@
var testUtils = require('../../../utils'), var testUtils = require('../../../utils'),
should = require('should'), should = require('should'),
supertest = require('supertest'), supertest = require('supertest'),
express = require('express'),
_ = require('lodash'), _ = require('lodash'),
ghost = require('../../../../../core'), ghost = require('../../../../../core'),
@ -14,12 +13,10 @@ describe('Post API', function () {
var accesstoken = ''; var accesstoken = '';
before(function (done) { before(function (done) {
var app = express();
// starting ghost automatically populates the db // starting ghost automatically populates the db
// TODO: prevent db init, and manage bringing up the DB with fixtures ourselves // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves
ghost({app: app}).then(function () { ghost().then(function (ghostServer) {
request = supertest.agent(app); request = supertest.agent(ghostServer.rootApp);
}).then(function () { }).then(function () {
return testUtils.doAuth(request, 'posts'); return testUtils.doAuth(request, 'posts');
}).then(function (token) { }).then(function (token) {

View File

@ -3,7 +3,6 @@
var testUtils = require('../../../utils'), var testUtils = require('../../../utils'),
should = require('should'), should = require('should'),
supertest = require('supertest'), supertest = require('supertest'),
express = require('express'),
ghost = require('../../../../../core'), ghost = require('../../../../../core'),
@ -13,12 +12,10 @@ describe('Settings API', function () {
var accesstoken = ''; var accesstoken = '';
before(function (done) { before(function (done) {
var app = express();
// starting ghost automatically populates the db // starting ghost automatically populates the db
// TODO: prevent db init, and manage bringing up the DB with fixtures ourselves // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves
ghost({app: app}).then(function () { ghost().then(function (ghostServer) {
request = supertest.agent(app); request = supertest.agent(ghostServer.rootApp);
}).then(function () { }).then(function () {
return testUtils.doAuth(request); return testUtils.doAuth(request);
}).then(function (token) { }).then(function (token) {

View File

@ -3,7 +3,6 @@
var testUtils = require('../../../utils'), var testUtils = require('../../../utils'),
should = require('should'), should = require('should'),
supertest = require('supertest'), supertest = require('supertest'),
express = require('express'),
ghost = require('../../../../../core'), ghost = require('../../../../../core'),
@ -13,12 +12,10 @@ describe('Slug API', function () {
var accesstoken = ''; var accesstoken = '';
before(function (done) { before(function (done) {
var app = express();
// starting ghost automatically populates the db // starting ghost automatically populates the db
// TODO: prevent db init, and manage bringing up the DB with fixtures ourselves // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves
ghost({app: app}).then(function () { ghost().then(function (ghostServer) {
request = supertest.agent(app); request = supertest.agent(ghostServer.rootApp);
}).then(function () { }).then(function () {
return testUtils.doAuth(request); return testUtils.doAuth(request);
}).then(function (token) { }).then(function (token) {

View File

@ -3,7 +3,6 @@
var testUtils = require('../../../utils'), var testUtils = require('../../../utils'),
should = require('should'), should = require('should'),
supertest = require('supertest'), supertest = require('supertest'),
express = require('express'),
ghost = require('../../../../../core'), ghost = require('../../../../../core'),
@ -13,12 +12,10 @@ describe('Tag API', function () {
var accesstoken = ''; var accesstoken = '';
before(function (done) { before(function (done) {
var app = express();
// starting ghost automatically populates the db // starting ghost automatically populates the db
// TODO: prevent db init, and manage bringing up the DB with fixtures ourselves // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves
ghost({app: app}).then(function () { ghost().then(function (ghostServer) {
request = supertest.agent(app); request = supertest.agent(ghostServer.rootApp);
}).then(function () { }).then(function () {
return testUtils.doAuth(request, 'posts'); return testUtils.doAuth(request, 'posts');
}).then(function (token) { }).then(function (token) {

View File

@ -3,7 +3,6 @@
var testUtils = require('../../../utils'), var testUtils = require('../../../utils'),
should = require('should'), should = require('should'),
supertest = require('supertest'), supertest = require('supertest'),
express = require('express'),
ghost = require('../../../../../core'), ghost = require('../../../../../core'),
@ -13,12 +12,10 @@ describe('User API', function () {
var accesstoken = ''; var accesstoken = '';
before(function (done) { before(function (done) {
var app = express();
// starting ghost automatically populates the db // starting ghost automatically populates the db
// TODO: prevent db init, and manage bringing up the DB with fixtures ourselves // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves
ghost({app: app}).then(function () { ghost().then(function (ghostServer) {
request = supertest.agent(app); request = supertest.agent(ghostServer.rootApp);
}).then(function () { }).then(function () {
return testUtils.doAuth(request); return testUtils.doAuth(request);
}).then(function (token) { }).then(function (token) {

View File

@ -6,7 +6,6 @@
// But then again testing real code, rather than mock code, might be more useful... // But then again testing real code, rather than mock code, might be more useful...
var request = require('supertest'), var request = require('supertest'),
express = require('express'),
should = require('should'), should = require('should'),
moment = require('moment'), moment = require('moment'),
@ -38,11 +37,9 @@ describe('Frontend Routing', function () {
} }
before(function (done) { before(function (done) {
var app = express(); ghost().then(function (ghostServer) {
ghost({app: app}).then(function () {
// Setup the request object with the ghost express app // Setup the request object with the ghost express app
request = request(app); request = request(ghostServer.rootApp);
done(); done();
}).catch(function (e) { }).catch(function (e) {

View File

@ -4,7 +4,7 @@ var testUtils = require('../../utils'),
should = require('should'), should = require('should'),
// Stuff we are testing // Stuff we are testing
AppFieldsModel = require('../../../server/models/appField').AppField, AppFieldsModel = require('../../../server/models/app-field').AppField,
context = testUtils.context.admin; context = testUtils.context.admin;
describe('App Fields Model', function () { describe('App Fields Model', function () {

View File

@ -4,7 +4,7 @@ var testUtils = require('../../utils'),
should = require('should'), should = require('should'),
// Stuff we are testing // Stuff we are testing
AppSettingModel = require('../../../server/models/appSetting').AppSetting, AppSettingModel = require('../../../server/models/app-setting').AppSetting,
context = testUtils.context.admin; context = testUtils.context.admin;
describe('App Setting Model', function () { describe('App Setting Model', function () {

View File

@ -76,11 +76,11 @@ describe('Middleware', function () {
}); });
describe('whenEnabled', function () { describe('whenEnabled', function () {
var cbFn, server; var cbFn, blogApp;
beforeEach(function () { beforeEach(function () {
cbFn = sinon.spy(); cbFn = sinon.spy();
server = { blogApp = {
enabled: function (setting) { enabled: function (setting) {
if (setting === 'enabled') { if (setting === 'enabled') {
return true; return true;
@ -89,7 +89,7 @@ describe('Middleware', function () {
} }
} }
}; };
middleware.cacheServer(server); middleware.cacheBlogApp(blogApp);
}); });
it('should call function if setting is enabled', function (done) { it('should call function if setting is enabled', function (done) {

View File

@ -7,8 +7,8 @@ var fs = require('fs-extra'),
rewire = require('rewire'), rewire = require('rewire'),
_ = require('lodash'), _ = require('lodash'),
config = rewire('../../server/config'), config = rewire('../../server/config'),
LocalFileStore = rewire('../../server/storage/localfilesystem'), LocalFileStore = rewire('../../server/storage/local-file-store'),
localfilesystem; localFileStore;
// To stop jshint complaining // To stop jshint complaining
should.equal(true, true); should.equal(true, true);
@ -39,7 +39,7 @@ describe('Local File System Storage', function () {
// Sat Sep 07 2013 21:24 // Sat Sep 07 2013 21:24
this.clock = sinon.useFakeTimers(new Date(2013, 8, 7, 21, 24).getTime()); this.clock = sinon.useFakeTimers(new Date(2013, 8, 7, 21, 24).getTime());
localfilesystem = new LocalFileStore(); localFileStore = new LocalFileStore();
}); });
afterEach(function () { afterEach(function () {
@ -51,7 +51,7 @@ describe('Local File System Storage', function () {
}); });
it('should send correct path to image when date is in Sep 2013', function (done) { it('should send correct path to image when date is in Sep 2013', function (done) {
localfilesystem.save(image).then(function (url) { localFileStore.save(image).then(function (url) {
url.should.equal('/content/images/2013/09/IMAGE.jpg'); url.should.equal('/content/images/2013/09/IMAGE.jpg');
return done(); return done();
}).catch(done); }).catch(done);
@ -59,7 +59,7 @@ describe('Local File System Storage', function () {
it('should send correct path to image when original file has spaces', function (done) { it('should send correct path to image when original file has spaces', function (done) {
image.name = 'AN IMAGE.jpg'; image.name = 'AN IMAGE.jpg';
localfilesystem.save(image).then(function (url) { localFileStore.save(image).then(function (url) {
url.should.equal('/content/images/2013/09/AN-IMAGE.jpg'); url.should.equal('/content/images/2013/09/AN-IMAGE.jpg');
return done(); return done();
}).catch(done); }).catch(done);
@ -68,14 +68,14 @@ describe('Local File System Storage', function () {
it('should send correct path to image when date is in Jan 2014', function (done) { it('should send correct path to image when date is in Jan 2014', function (done) {
// Jan 1 2014 12:00 // Jan 1 2014 12:00
this.clock = sinon.useFakeTimers(new Date(2014, 0, 1, 12).getTime()); this.clock = sinon.useFakeTimers(new Date(2014, 0, 1, 12).getTime());
localfilesystem.save(image).then(function (url) { localFileStore.save(image).then(function (url) {
url.should.equal('/content/images/2014/01/IMAGE.jpg'); url.should.equal('/content/images/2014/01/IMAGE.jpg');
return done(); return done();
}).catch(done); }).catch(done);
}); });
it('should create month and year directory', function (done) { it('should create month and year directory', function (done) {
localfilesystem.save(image).then(function (url) { localFileStore.save(image).then(function (url) {
/*jshint unused:false*/ /*jshint unused:false*/
fs.mkdirs.calledOnce.should.be.true; fs.mkdirs.calledOnce.should.be.true;
fs.mkdirs.args[0][0].should.equal(path.resolve('./content/images/2013/09')); fs.mkdirs.args[0][0].should.equal(path.resolve('./content/images/2013/09'));
@ -84,7 +84,7 @@ describe('Local File System Storage', function () {
}); });
it('should copy temp file to new location', function (done) { it('should copy temp file to new location', function (done) {
localfilesystem.save(image).then(function (url) { localFileStore.save(image).then(function (url) {
/*jshint unused:false*/ /*jshint unused:false*/
fs.copy.calledOnce.should.be.true; fs.copy.calledOnce.should.be.true;
fs.copy.args[0][0].should.equal('tmp/123456.jpg'); fs.copy.args[0][0].should.equal('tmp/123456.jpg');
@ -104,7 +104,7 @@ describe('Local File System Storage', function () {
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(true); fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(true);
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(false); fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(false);
localfilesystem.save(image).then(function (url) { localFileStore.save(image).then(function (url) {
url.should.equal('/content/images/2013/09/IMAGE-1.jpg'); url.should.equal('/content/images/2013/09/IMAGE-1.jpg');
return done(); return done();
}).catch(done); }).catch(done);
@ -126,7 +126,7 @@ describe('Local File System Storage', function () {
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-3.jpg')).yields(true); fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-3.jpg')).yields(true);
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-4.jpg')).yields(false); fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-4.jpg')).yields(false);
localfilesystem.save(image).then(function (url) { localFileStore.save(image).then(function (url) {
url.should.equal('/content/images/2013/09/IMAGE-4.jpg'); url.should.equal('/content/images/2013/09/IMAGE-4.jpg');
return done(); return done();
}).catch(done); }).catch(done);
@ -147,7 +147,7 @@ describe('Local File System Storage', function () {
}); });
it('should send the correct path to image', function (done) { it('should send the correct path to image', function (done) {
localfilesystem.save(image).then(function (url) { localFileStore.save(image).then(function (url) {
url.should.equal('/content/images/2013/09/IMAGE.jpg'); url.should.equal('/content/images/2013/09/IMAGE.jpg');
return done(); return done();
}).catch(done); }).catch(done);
@ -169,7 +169,7 @@ describe('Local File System Storage', function () {
it('should return url in proper format for windows', function (done) { it('should return url in proper format for windows', function (done) {
path.sep = '\\'; path.sep = '\\';
path.join.returns('content\\images\\2013\\09\\IMAGE.jpg'); path.join.returns('content\\images\\2013\\09\\IMAGE.jpg');
localfilesystem.save(image).then(function (url) { localFileStore.save(image).then(function (url) {
if (truePathSep === '\\') { if (truePathSep === '\\') {
url.should.equal('/content/images/2013/09/IMAGE.jpg'); url.should.equal('/content/images/2013/09/IMAGE.jpg');
} else { } else {

View File

@ -6,14 +6,14 @@ var express = require('express'),
ghost = require('./core'), ghost = require('./core'),
errors = require('./core/server/errors'), errors = require('./core/server/errors'),
// Create our parent express app instance. // Create our parent express app instance.
server = express(); parentApp = express();
ghost().then(function (instance) { ghost().then(function (ghostServer) {
// Mount our ghost instance on our desired subdirectory path if it exists. // Mount our ghost instance on our desired subdirectory path if it exists.
server.use(instance.config.paths.subdir, instance.app); parentApp.use(ghostServer.config.paths.subdir, ghostServer.rootApp);
// Let ghost handle starting our server instance. // Let ghost handle starting our server instance.
instance.start(server); ghostServer.start(parentApp);
}).catch(function (err) { }).catch(function (err) {
errors.logErrorAndExit(err, err.context, err.help); errors.logErrorAndExit(err, err.context, err.help);
}); });