diff --git a/core/server/errors/badrequesterror.js b/core/server/errors/bad-request-error.js similarity index 100% rename from core/server/errors/badrequesterror.js rename to core/server/errors/bad-request-error.js diff --git a/core/server/errors/dataimporterror.js b/core/server/errors/data-import-error.js similarity index 100% rename from core/server/errors/dataimporterror.js rename to core/server/errors/data-import-error.js diff --git a/core/server/errors/emailerror.js b/core/server/errors/email-error.js similarity index 100% rename from core/server/errors/emailerror.js rename to core/server/errors/email-error.js diff --git a/core/server/errors/index.js b/core/server/errors/index.js index 2f6fbc91ce..4a8b4ffd71 100644 --- a/core/server/errors/index.js +++ b/core/server/errors/index.js @@ -4,16 +4,16 @@ var _ = require('lodash'), path = require('path'), Promise = require('bluebird'), hbs = require('express-hbs'), - NotFoundError = require('./notfounderror'), - BadRequestError = require('./badrequesterror'), - InternalServerError = require('./internalservererror'), - NoPermissionError = require('./nopermissionerror'), - RequestEntityTooLargeError = require('./requesttoolargeerror'), - UnauthorizedError = require('./unauthorizederror'), - ValidationError = require('./validationerror'), - UnsupportedMediaTypeError = require('./unsupportedmediaerror'), - EmailError = require('./emailerror'), - DataImportError = require('./dataimporterror'), + NotFoundError = require('./not-found-error'), + BadRequestError = require('./bad-request-error'), + InternalServerError = require('./internal-server-error'), + NoPermissionError = require('./no-permission-error'), + RequestEntityTooLargeError = require('./request-too-large-error'), + UnauthorizedError = require('./unauthorized-error'), + ValidationError = require('./validation-error'), + UnsupportedMediaTypeError = require('./unsupported-media-type-error'), + EmailError = require('./email-error'), + DataImportError = require('./data-import-error'), config, errors, diff --git a/core/server/errors/internalservererror.js b/core/server/errors/internal-server-error.js similarity index 100% rename from core/server/errors/internalservererror.js rename to core/server/errors/internal-server-error.js diff --git a/core/server/errors/nopermissionerror.js b/core/server/errors/no-permission-error.js similarity index 100% rename from core/server/errors/nopermissionerror.js rename to core/server/errors/no-permission-error.js diff --git a/core/server/errors/notfounderror.js b/core/server/errors/not-found-error.js similarity index 100% rename from core/server/errors/notfounderror.js rename to core/server/errors/not-found-error.js diff --git a/core/server/errors/requesttoolargeerror.js b/core/server/errors/request-too-large-error.js similarity index 100% rename from core/server/errors/requesttoolargeerror.js rename to core/server/errors/request-too-large-error.js diff --git a/core/server/errors/unauthorizederror.js b/core/server/errors/unauthorized-error.js similarity index 100% rename from core/server/errors/unauthorizederror.js rename to core/server/errors/unauthorized-error.js diff --git a/core/server/errors/unsupportedmediaerror.js b/core/server/errors/unsupported-media-type-error.js similarity index 100% rename from core/server/errors/unsupportedmediaerror.js rename to core/server/errors/unsupported-media-type-error.js diff --git a/core/server/errors/validationerror.js b/core/server/errors/validation-error.js similarity index 100% rename from core/server/errors/validationerror.js rename to core/server/errors/validation-error.js diff --git a/core/server/GhostServer.js b/core/server/ghost-server.js similarity index 96% rename from core/server/GhostServer.js rename to core/server/ghost-server.js index 76f2ace352..bb094dc713 100644 --- a/core/server/GhostServer.js +++ b/core/server/ghost-server.js @@ -4,8 +4,8 @@ var Promise = require('bluebird'), packageInfo = require('../../package.json'), config = require('./config'); -function GhostServer(app) { - this.app = app; +function GhostServer(rootApp) { + this.rootApp = rootApp; this.httpServer = null; this.connections = []; this.upgradeWarning = setTimeout(this.logUpgradeWarning.bind(this), 5000); @@ -98,7 +98,7 @@ GhostServer.prototype.logUpgradeWarning = function () { */ GhostServer.prototype.start = function (externalApp) { var self = this, - app = externalApp ? externalApp : self.app; + rootApp = externalApp ? externalApp : self.rootApp; // ## Start Ghost App return new Promise(function (resolve) { @@ -110,13 +110,13 @@ GhostServer.prototype.start = function (externalApp) { // We can ignore this. } - self.httpServer = app.listen( + self.httpServer = rootApp.listen( config.getSocket() ); fs.chmod(config.getSocket(), '0660'); } else { - self.httpServer = app.listen( + self.httpServer = rootApp.listen( config.server.port, config.server.host ); diff --git a/core/server/index.js b/core/server/index.js index 513e41593c..86968dade2 100644 --- a/core/server/index.js +++ b/core/server/index.js @@ -19,7 +19,7 @@ var crypto = require('crypto'), permissions = require('./permissions'), apps = require('./apps'), packageInfo = require('../../package.json'), - GhostServer = require('./GhostServer'), + GhostServer = require('./ghost-server'), // Variables dbHash; @@ -131,8 +131,8 @@ function initNotifications() { // Finally it returns an instance of GhostServer function init(options) { // Get reference to an express app instance. - var server = options.app ? options.app : express(), - adminExpress = express(), + var blogApp = express(), + adminApp = express(), // create a hash for cache busting assets 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 if (config.server.compress !== false) { - server.use(compress()); + blogApp.use(compress()); } // ## 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 - adminExpress.set('view engine', 'hbs'); - adminExpress.engine('hbs', adminHbs.express3({})); + adminApp.set('view engine', 'hbs'); + adminApp.engine('hbs', adminHbs.express3({})); // Load helpers helpers.loadCoreHelpers(adminHbs, assetHash); // ## Middleware and Routing - middleware(server, adminExpress); + middleware(blogApp, adminApp); // Log all theme errors and warnings _.each(config.paths.availableThemes._messages.errors, function (error) { @@ -210,7 +210,7 @@ function init(options) { errors.logWarn(warn.message, warn.context, warn.help); }); - return new GhostServer(server); + return new GhostServer(blogApp); }); } diff --git a/core/server/middleware/authStrategies.js b/core/server/middleware/auth-strategies.js similarity index 100% rename from core/server/middleware/authStrategies.js rename to core/server/middleware/auth-strategies.js diff --git a/core/server/middleware/index.js b/core/server/middleware/index.js index 5639e577d9..6fceffb119 100644 --- a/core/server/middleware/index.js +++ b/core/server/middleware/index.js @@ -22,10 +22,10 @@ var api = require('../api'), passport = require('passport'), oauth = require('./oauth'), oauth2orize = require('oauth2orize'), - authStrategies = require('./authStrategies'), + authStrategies = require('./auth-strategies'), utils = require('../utils'), - expressServer, + blogApp, setupMiddleware; // ##Custom Middleware @@ -50,7 +50,7 @@ function activateTheme(activeTheme) { themePartials = path.join(config.paths.themePath, activeTheme, 'partials'); // clear the view cache - expressServer.cache = {}; + blogApp.cache = {}; // set view engine 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 errors.updateActiveTheme(activeTheme); // Set active theme variable on the express server - expressServer.set('activeTheme', activeTheme); + blogApp.set('activeTheme', activeTheme); } // ### decideIsAdmin Middleware // 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}}); - 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 // so that templates can choose 'url' vs 'urlSSL' @@ -99,14 +99,14 @@ function configHbsForContext(req, res, next) { } // ### 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 // is not yet activated. function updateActiveTheme(req, res, next) { api.settings.read({context: {internal: true}, key: 'activeTheme'}).then(function (response) { var activeTheme = response.settings[0]; // Check if the theme changed - if (activeTheme.value !== expressServer.get('activeTheme')) { + if (activeTheme.value !== blogApp.get('activeTheme')) { // Change theme if (!config.paths.availableThemes.hasOwnProperty(activeTheme.value)) { if (!res.isAdmin) { @@ -121,7 +121,7 @@ function updateActiveTheme(req, res, next) { }).catch(function (err) { // Trying to start up without the active theme present, setup a simple hbs instance // and render an error page straight away. - expressServer.engine('hbs', hbs.express3()); + blogApp.engine('hbs', hbs.express3()); next(err); }); } @@ -235,7 +235,7 @@ function serveSharedFile(file, type, maxAge) { }; } -setupMiddleware = function (server, adminExpress) { +setupMiddleware = function (blogAppInstance, adminApp) { var logging = config.logging, corePath = config.paths.corePath, oauthServer = oauth2orize.createServer(); @@ -244,98 +244,98 @@ setupMiddleware = function (server, adminExpress) { authStrategies = authStrategies; // Cache express server instance - expressServer = server; - middleware.cacheServer(expressServer); + blogApp = blogAppInstance; + middleware.cacheBlogApp(blogApp); middleware.cacheOauthServer(oauthServer); oauth.init(oauthServer, middleware.resetSpamCounter); // Make sure 'req.secure' is valid for proxied requests // (X-Forwarded-Proto header will be checked, if present) - expressServer.enable('trust proxy'); + blogApp.enable('trust proxy'); // Logging configuration if (logging !== false) { - if (expressServer.get('env') !== 'development') { - expressServer.use(logger('combined', logging)); + if (blogApp.get('env') !== 'development') { + blogApp.use(logger('combined', logging)); } else { - expressServer.use(logger('dev', logging)); + blogApp.use(logger('dev', logging)); } } // 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 - expressServer.use('/shared', express['static'](path.join(corePath, '/shared'), {maxAge: utils.ONE_HOUR_MS})); - expressServer.use('/content/images', storage.getStorage().serve()); - expressServer.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('/shared', express['static'](path.join(corePath, '/shared'), {maxAge: utils.ONE_HOUR_MS})); + blogApp.use('/content/images', storage.getStorage().serve()); + blogApp.use('/ghost/scripts', express['static'](path.join(corePath, '/built/scripts'), {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 - expressServer.use(decideIsAdmin); - expressServer.use(updateActiveTheme); - expressServer.use(configHbsForContext); + blogApp.use(decideIsAdmin); + blogApp.use(updateActiveTheme); + blogApp.use(configHbsForContext); // 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 // 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 // not display properly when HTTPS is not available! - expressServer.use(checkSSL); - adminExpress.set('views', config.paths.adminViews); + blogApp.use(checkSSL); + adminApp.set('views', config.paths.adminViews); // Theme only config - expressServer.use(middleware.staticTheme()); + blogApp.use(middleware.staticTheme()); // 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 // in the redirect. - expressServer.use(slashes(true, { + blogApp.use(slashes(true, { headers: { 'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S }, base: config.paths.subdir })); - expressServer.use(uncapitalise); + blogApp.use(uncapitalise); // Body parsing - expressServer.use(bodyParser.json()); - expressServer.use(bodyParser.urlencoded({extended: true})); + blogApp.use(bodyParser.json()); + blogApp.use(bodyParser.urlencoded({extended: true})); - expressServer.use(passport.initialize()); + blogApp.use(passport.initialize()); // ### Caching - expressServer.use(middleware.cacheControl('public')); - adminExpress.use(middleware.cacheControl('private')); + blogApp.use(middleware.cacheControl('public')); + adminApp.use(middleware.cacheControl('private')); // enable authentication - expressServer.use(middleware.authenticate); + blogApp.use(middleware.authenticate); // local data - expressServer.use(ghostLocals); + blogApp.use(ghostLocals); // ### Routing // 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 - adminExpress.use(middleware.redirectToSetup); - adminExpress.use(routes.admin()); - expressServer.use('/ghost', adminExpress); + adminApp.use(middleware.redirectToSetup); + adminApp.use(routes.admin()); + blogApp.use('/ghost', adminApp); // Set up Frontend routes - expressServer.use(routes.frontend()); + blogApp.use(routes.frontend()); // ### Error handling // 404 Handler - expressServer.use(errors.error404); + blogApp.use(errors.error404); // 500 Handler - expressServer.use(errors.error500); + blogApp.use(errors.error500); }; module.exports = setupMiddleware; diff --git a/core/server/middleware/middleware.js b/core/server/middleware/middleware.js index 5761d3becc..04962ad4c1 100644 --- a/core/server/middleware/middleware.js +++ b/core/server/middleware/middleware.js @@ -13,7 +13,7 @@ var _ = require('lodash'), utils = require('../utils'), middleware, - expressServer, + blogApp, oauthServer, loginSecurity = [], forgottenSecurity = []; @@ -24,8 +24,8 @@ function isBlackListedFileType(file) { return _.contains(blackListedFileTypes, ext); } -function cacheServer(server) { - expressServer = server; +function cacheBlogApp(app) { + blogApp = app; } function cacheOauthServer(server) { @@ -105,7 +105,7 @@ middleware = { whenEnabled: function (setting, fn) { return function settingEnabled(req, res, next) { // Set from server/middleware/index.js for now - if (expressServer.enabled(setting)) { + if (blogApp.enabled(setting)) { fn(req, res, next); } else { next(); @@ -263,5 +263,5 @@ middleware = { }; module.exports = middleware; -module.exports.cacheServer = cacheServer; +module.exports.cacheBlogApp = cacheBlogApp; module.exports.cacheOauthServer = cacheOauthServer; diff --git a/core/server/models/appField.js b/core/server/models/app-field.js similarity index 100% rename from core/server/models/appField.js rename to core/server/models/app-field.js diff --git a/core/server/models/appSetting.js b/core/server/models/app-setting.js similarity index 100% rename from core/server/models/appSetting.js rename to core/server/models/app-setting.js diff --git a/core/server/models/base.js b/core/server/models/base.js index d8e77ea05f..a7b77cefc2 100644 --- a/core/server/models/base.js +++ b/core/server/models/base.js @@ -282,13 +282,13 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({ add: function (data, options) { data = this.filterData(data); 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 // as the import json blob. More details refer to https://github.com/TryGhost/Ghost/issues/1696 if (options.importing) { - instance.hasTimestamps = false; + model.hasTimestamps = false; } - return instance.save(null, options); + return model.save(null, options); }, /** diff --git a/core/server/permissions/index.js b/core/server/permissions/index.js index 42d5c0c91e..a9781c5f7d 100644 --- a/core/server/permissions/index.js +++ b/core/server/permissions/index.js @@ -51,7 +51,7 @@ CanThisResult = function () { CanThisResult.prototype.buildObjectTypeHandlers = function (objTypes, actType, context, permissionLoad) { // @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'] return _.reduce(objTypes, function (objTypeHandlers, objType) { diff --git a/core/server/permissions/objectTypeModelMap.js b/core/server/permissions/object-type-model-map.js similarity index 100% rename from core/server/permissions/objectTypeModelMap.js rename to core/server/permissions/object-type-model-map.js diff --git a/core/server/storage/index.js b/core/server/storage/index.js index f680f277b3..6f8cf211a0 100644 --- a/core/server/storage/index.js +++ b/core/server/storage/index.js @@ -4,7 +4,7 @@ var errors = require('../errors'), function getStorage(storageChoice) { // TODO: this is where the check for storage apps should go // Local file system is the default. Fow now that is all we support. - storageChoice = 'localfilesystem'; + storageChoice = 'local-file-store'; if (storage[storageChoice]) { return storage[storageChoice]; diff --git a/core/server/storage/localfilesystem.js b/core/server/storage/local-file-store.js similarity index 100% rename from core/server/storage/localfilesystem.js rename to core/server/storage/local-file-store.js diff --git a/core/test/functional/routes/admin_test.js b/core/test/functional/routes/admin_test.js index a71e31eb90..a16b2582ca 100644 --- a/core/test/functional/routes/admin_test.js +++ b/core/test/functional/routes/admin_test.js @@ -6,7 +6,6 @@ // But then again testing real code, rather than mock code, might be more useful... var request = require('supertest'), - express = require('express'), should = require('should'), testUtils = require('../../utils'), @@ -47,11 +46,9 @@ describe('Admin Routing', function () { } before(function (done) { - var app = express(); - - ghost({app: app}).then(function () { + ghost().then(function (ghostServer) { // Setup the request object with the ghost express app - request = request(app); + request = request(ghostServer.rootApp); done(); }).catch(function (e) { diff --git a/core/test/functional/routes/api/authentication_test.js b/core/test/functional/routes/api/authentication_test.js index db5867925b..3c701d34cd 100644 --- a/core/test/functional/routes/api/authentication_test.js +++ b/core/test/functional/routes/api/authentication_test.js @@ -1,7 +1,6 @@ /*global describe, it, before, after */ /*jshint expr:true*/ var supertest = require('supertest'), - express = require('express'), should = require('should'), testUtils = require('../../../utils'), user = testUtils.DataGenerator.forModel.users[0], @@ -12,12 +11,10 @@ describe('Authentication API', function () { var accesstoken = ''; before(function (done) { - var app = express(); - // starting ghost automatically populates the db // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves - ghost({app: app}).then(function () { - request = supertest.agent(app); + ghost().then(function (ghostServer) { + request = supertest.agent(ghostServer.rootApp); }).then(function () { return testUtils.doAuth(request); }).then(function (token) { diff --git a/core/test/functional/routes/api/db_test.js b/core/test/functional/routes/api/db_test.js index d33384d4e8..6a0afa8e03 100644 --- a/core/test/functional/routes/api/db_test.js +++ b/core/test/functional/routes/api/db_test.js @@ -1,7 +1,6 @@ /*global describe, it, before, after */ /*jshint expr:true*/ var supertest = require('supertest'), - express = require('express'), should = require('should'), testUtils = require('../../../utils'), ghost = require('../../../../../core'), @@ -11,12 +10,10 @@ describe('DB API', function () { var accesstoken = ''; before(function (done) { - var app = express(); - // starting ghost automatically populates the db // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves - ghost({app: app}).then(function () { - request = supertest.agent(app); + ghost().then(function (ghostServer) { + request = supertest.agent(ghostServer.rootApp); }).then(function () { return testUtils.doAuth(request); }).then(function (token) { diff --git a/core/test/functional/routes/api/error_test.js b/core/test/functional/routes/api/error_test.js index 39dbecc118..ffd155fdaf 100644 --- a/core/test/functional/routes/api/error_test.js +++ b/core/test/functional/routes/api/error_test.js @@ -6,7 +6,6 @@ // But then again testing real code, rather than mock code, might be more useful... var supertest = require('supertest'), - express = require('express'), should = require('should'), testUtils = require('../../../utils'), @@ -15,10 +14,8 @@ var supertest = require('supertest'), describe('Unauthorized', function () { before(function (done) { - var app = express(); - - ghost({app: app}).then(function () { - request = supertest.agent(app); + ghost().then(function (ghostServer) { + request = supertest.agent(ghostServer.rootApp); done(); }); diff --git a/core/test/functional/routes/api/notifications_test.js b/core/test/functional/routes/api/notifications_test.js index 05eb93ffc2..ea3fde58d6 100644 --- a/core/test/functional/routes/api/notifications_test.js +++ b/core/test/functional/routes/api/notifications_test.js @@ -2,7 +2,6 @@ /*jshint expr:true*/ var testUtils = require('../../../utils'), supertest = require('supertest'), - express = require('express'), ghost = require('../../../../../core'), @@ -12,12 +11,10 @@ describe('Notifications API', function () { var accesstoken = ''; before(function (done) { - var app = express(); - // starting ghost automatically populates the db // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves - ghost({app: app}).then(function () { - request = supertest.agent(app); + ghost().then(function (ghostServer) { + request = supertest.agent(ghostServer.rootApp); }).then(function () { return testUtils.doAuth(request); }).then(function (token) { diff --git a/core/test/functional/routes/api/posts_test.js b/core/test/functional/routes/api/posts_test.js index bfba99f182..c50da25024 100644 --- a/core/test/functional/routes/api/posts_test.js +++ b/core/test/functional/routes/api/posts_test.js @@ -3,7 +3,6 @@ var testUtils = require('../../../utils'), should = require('should'), supertest = require('supertest'), - express = require('express'), _ = require('lodash'), ghost = require('../../../../../core'), @@ -14,12 +13,10 @@ describe('Post API', function () { var accesstoken = ''; before(function (done) { - var app = express(); - // starting ghost automatically populates the db // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves - ghost({app: app}).then(function () { - request = supertest.agent(app); + ghost().then(function (ghostServer) { + request = supertest.agent(ghostServer.rootApp); }).then(function () { return testUtils.doAuth(request, 'posts'); }).then(function (token) { diff --git a/core/test/functional/routes/api/settings_test.js b/core/test/functional/routes/api/settings_test.js index 4e0f534cf2..a0948b78f1 100644 --- a/core/test/functional/routes/api/settings_test.js +++ b/core/test/functional/routes/api/settings_test.js @@ -3,7 +3,6 @@ var testUtils = require('../../../utils'), should = require('should'), supertest = require('supertest'), - express = require('express'), ghost = require('../../../../../core'), @@ -13,12 +12,10 @@ describe('Settings API', function () { var accesstoken = ''; before(function (done) { - var app = express(); - // starting ghost automatically populates the db // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves - ghost({app: app}).then(function () { - request = supertest.agent(app); + ghost().then(function (ghostServer) { + request = supertest.agent(ghostServer.rootApp); }).then(function () { return testUtils.doAuth(request); }).then(function (token) { diff --git a/core/test/functional/routes/api/slugs_test.js b/core/test/functional/routes/api/slugs_test.js index d5192d18c9..99235e98a9 100644 --- a/core/test/functional/routes/api/slugs_test.js +++ b/core/test/functional/routes/api/slugs_test.js @@ -3,7 +3,6 @@ var testUtils = require('../../../utils'), should = require('should'), supertest = require('supertest'), - express = require('express'), ghost = require('../../../../../core'), @@ -13,12 +12,10 @@ describe('Slug API', function () { var accesstoken = ''; before(function (done) { - var app = express(); - // starting ghost automatically populates the db // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves - ghost({app: app}).then(function () { - request = supertest.agent(app); + ghost().then(function (ghostServer) { + request = supertest.agent(ghostServer.rootApp); }).then(function () { return testUtils.doAuth(request); }).then(function (token) { diff --git a/core/test/functional/routes/api/tags_test.js b/core/test/functional/routes/api/tags_test.js index 7a64d2c435..ac5ab97ae2 100644 --- a/core/test/functional/routes/api/tags_test.js +++ b/core/test/functional/routes/api/tags_test.js @@ -3,7 +3,6 @@ var testUtils = require('../../../utils'), should = require('should'), supertest = require('supertest'), - express = require('express'), ghost = require('../../../../../core'), @@ -13,12 +12,10 @@ describe('Tag API', function () { var accesstoken = ''; before(function (done) { - var app = express(); - // starting ghost automatically populates the db // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves - ghost({app: app}).then(function () { - request = supertest.agent(app); + ghost().then(function (ghostServer) { + request = supertest.agent(ghostServer.rootApp); }).then(function () { return testUtils.doAuth(request, 'posts'); }).then(function (token) { diff --git a/core/test/functional/routes/api/users_test.js b/core/test/functional/routes/api/users_test.js index cb03b42f7b..434e8a21b4 100644 --- a/core/test/functional/routes/api/users_test.js +++ b/core/test/functional/routes/api/users_test.js @@ -3,7 +3,6 @@ var testUtils = require('../../../utils'), should = require('should'), supertest = require('supertest'), - express = require('express'), ghost = require('../../../../../core'), @@ -13,12 +12,10 @@ describe('User API', function () { var accesstoken = ''; before(function (done) { - var app = express(); - // starting ghost automatically populates the db // TODO: prevent db init, and manage bringing up the DB with fixtures ourselves - ghost({app: app}).then(function () { - request = supertest.agent(app); + ghost().then(function (ghostServer) { + request = supertest.agent(ghostServer.rootApp); }).then(function () { return testUtils.doAuth(request); }).then(function (token) { diff --git a/core/test/functional/routes/frontend_test.js b/core/test/functional/routes/frontend_test.js index 4f18f1683e..d794b7ddc8 100644 --- a/core/test/functional/routes/frontend_test.js +++ b/core/test/functional/routes/frontend_test.js @@ -6,7 +6,6 @@ // But then again testing real code, rather than mock code, might be more useful... var request = require('supertest'), - express = require('express'), should = require('should'), moment = require('moment'), @@ -38,11 +37,9 @@ describe('Frontend Routing', function () { } before(function (done) { - var app = express(); - - ghost({app: app}).then(function () { + ghost().then(function (ghostServer) { // Setup the request object with the ghost express app - request = request(app); + request = request(ghostServer.rootApp); done(); }).catch(function (e) { diff --git a/core/test/integration/model/model_app_fields_spec.js b/core/test/integration/model/model_app-fields_spec.js similarity index 95% rename from core/test/integration/model/model_app_fields_spec.js rename to core/test/integration/model/model_app-fields_spec.js index dc4eabbd78..13e1148acd 100644 --- a/core/test/integration/model/model_app_fields_spec.js +++ b/core/test/integration/model/model_app-fields_spec.js @@ -4,7 +4,7 @@ var testUtils = require('../../utils'), should = require('should'), // Stuff we are testing - AppFieldsModel = require('../../../server/models/appField').AppField, + AppFieldsModel = require('../../../server/models/app-field').AppField, context = testUtils.context.admin; describe('App Fields Model', function () { diff --git a/core/test/integration/model/model_app_settings_spec.js b/core/test/integration/model/model_app-settings_spec.js similarity index 95% rename from core/test/integration/model/model_app_settings_spec.js rename to core/test/integration/model/model_app-settings_spec.js index 4829a50a90..56e4131c88 100644 --- a/core/test/integration/model/model_app_settings_spec.js +++ b/core/test/integration/model/model_app-settings_spec.js @@ -4,7 +4,7 @@ var testUtils = require('../../utils'), should = require('should'), // Stuff we are testing - AppSettingModel = require('../../../server/models/appSetting').AppSetting, + AppSettingModel = require('../../../server/models/app-setting').AppSetting, context = testUtils.context.admin; describe('App Setting Model', function () { diff --git a/core/test/unit/errorHandling_spec.js b/core/test/unit/error_handling_spec.js similarity index 100% rename from core/test/unit/errorHandling_spec.js rename to core/test/unit/error_handling_spec.js diff --git a/core/test/unit/middleware_spec.js b/core/test/unit/middleware_spec.js index 1dd7ac6012..0e19320d1f 100644 --- a/core/test/unit/middleware_spec.js +++ b/core/test/unit/middleware_spec.js @@ -76,11 +76,11 @@ describe('Middleware', function () { }); describe('whenEnabled', function () { - var cbFn, server; + var cbFn, blogApp; beforeEach(function () { cbFn = sinon.spy(); - server = { + blogApp = { enabled: function (setting) { if (setting === 'enabled') { 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) { diff --git a/core/test/unit/storage_localfilesystem_spec.js b/core/test/unit/storage_local-file-store_spec.js similarity index 91% rename from core/test/unit/storage_localfilesystem_spec.js rename to core/test/unit/storage_local-file-store_spec.js index 4aaf4075dc..afc8c26f7c 100644 --- a/core/test/unit/storage_localfilesystem_spec.js +++ b/core/test/unit/storage_local-file-store_spec.js @@ -7,8 +7,8 @@ var fs = require('fs-extra'), rewire = require('rewire'), _ = require('lodash'), config = rewire('../../server/config'), - LocalFileStore = rewire('../../server/storage/localfilesystem'), - localfilesystem; + LocalFileStore = rewire('../../server/storage/local-file-store'), + localFileStore; // To stop jshint complaining should.equal(true, true); @@ -39,7 +39,7 @@ describe('Local File System Storage', function () { // Sat Sep 07 2013 21:24 this.clock = sinon.useFakeTimers(new Date(2013, 8, 7, 21, 24).getTime()); - localfilesystem = new LocalFileStore(); + localFileStore = new LocalFileStore(); }); 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) { - localfilesystem.save(image).then(function (url) { + localFileStore.save(image).then(function (url) { url.should.equal('/content/images/2013/09/IMAGE.jpg'); return 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) { 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'); return 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) { // Jan 1 2014 12:00 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'); return done(); }).catch(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*/ fs.mkdirs.calledOnce.should.be.true; 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) { - localfilesystem.save(image).then(function (url) { + localFileStore.save(image).then(function (url) { /*jshint unused:false*/ fs.copy.calledOnce.should.be.true; 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-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'); return 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-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'); return done(); }).catch(done); @@ -147,7 +147,7 @@ describe('Local File System Storage', function () { }); 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'); return done(); }).catch(done); @@ -169,7 +169,7 @@ describe('Local File System Storage', function () { it('should return url in proper format for windows', function (done) { path.sep = '\\'; path.join.returns('content\\images\\2013\\09\\IMAGE.jpg'); - localfilesystem.save(image).then(function (url) { + localFileStore.save(image).then(function (url) { if (truePathSep === '\\') { url.should.equal('/content/images/2013/09/IMAGE.jpg'); } else { diff --git a/index.js b/index.js index 37944c1b87..70c93fb560 100644 --- a/index.js +++ b/index.js @@ -6,14 +6,14 @@ var express = require('express'), ghost = require('./core'), errors = require('./core/server/errors'), // 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. - server.use(instance.config.paths.subdir, instance.app); + parentApp.use(ghostServer.config.paths.subdir, ghostServer.rootApp); // Let ghost handle starting our server instance. - instance.start(server); + ghostServer.start(parentApp); }).catch(function (err) { errors.logErrorAndExit(err, err.context, err.help); });