Skip to content

Commit

Permalink
Moved app handling code into services/apps
Browse files Browse the repository at this point in the history
refs TryGhost#9178

- Apps is a service, that allows for the App lifecycle
- /server/apps = contains internal apps
- /server/services/apps = contains code for managing/handling app life cycle, providing the proxy, etc
  • Loading branch information
ErisDS committed Oct 28, 2017
1 parent 17e18d7 commit b48c5e8
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 42 deletions.
11 changes: 6 additions & 5 deletions core/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ require('./overrides');

// Module dependencies
var debug = require('ghost-ignition').debug('boot:init'),
// Config should be first require, as it triggers the initial load of the config files
config = require('./config'),
Promise = require('bluebird'),
i18n = require('./i18n'),
models = require('./models'),
permissions = require('./permissions'),
apps = require('./apps'),
auth = require('./auth'),
dbHealth = require('./data/db/health'),
xmlrpc = require('./services/xmlrpc'),
slack = require('./services/slack'),
GhostServer = require('./ghost-server'),
scheduling = require('./adapters/scheduling'),
settings = require('./settings'),
themes = require('./themes'),
utils = require('./utils');
utils = require('./utils'),

// Services that need initialisation
apps = require('./services/apps'),
xmlrpc = require('./services/xmlrpc'),
slack = require('./services/slack');

// ## Initialise Ghost
function init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

var _ = require('lodash'),
fs = require('fs'),
path = require('path'),
Expand Down
17 changes: 8 additions & 9 deletions core/server/apps/index.js → core/server/services/apps/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

var _ = require('lodash'),
Promise = require('bluebird'),
logging = require('../logging'),
errors = require('../errors'),
api = require('../api'),
loader = require('./loader'),
i18n = require('../i18n'),
config = require('../config'),
var _ = require('lodash'),
Promise = require('bluebird'),
logging = require('../../logging'),
errors = require('../../errors'),
api = require('../../api'),
i18n = require('../../i18n'),
config = require('../../config'),
loader = require('./loader'),
// Holds the available apps
availableApps = {};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

var path = require('path'),
_ = require('lodash'),
Promise = require('bluebird'),
config = require('../../config'),
i18n = require('../../i18n'),

AppProxy = require('./proxy'),
config = require('../config'),
AppSandbox = require('./sandbox'),
AppDependencies = require('./dependencies'),
AppPermissions = require('./permissions'),
i18n = require('../i18n'),

loader;

function isInternalApp(name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var fs = require('fs'),
Promise = require('bluebird'),
path = require('path'),
parsePackageJson = require('../utils/packages').parsePackageJSON;
parsePackageJson = require('../../utils/packages').parsePackageJSON;

function AppPermissions(appPath) {
this.appPath = appPath;
Expand Down
10 changes: 5 additions & 5 deletions core/server/apps/proxy.js → core/server/services/apps/proxy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var _ = require('lodash'),
api = require('../api'),
helpers = require('../helpers/register'),
filters = require('../filters'),
i18n = require('../i18n'),
var _ = require('lodash'),
api = require('../../api'),
helpers = require('../../helpers/register'),
filters = require('../../filters'),
i18n = require('../../i18n'),
generateProxyFunctions;

generateProxyFunctions = function (name, permissions, isInternal) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

var path = require('path'),
Module = require('module'),
i18n = require('../i18n'),
_ = require('lodash');
var path = require('path'),
Module = require('module'),
i18n = require('../../i18n'),
_ = require('lodash');

function AppSandbox(opts) {
this.opts = _.defaults(opts || {}, AppSandbox.defaults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ var should = require('should'),
EventEmitter = require('events').EventEmitter,
_ = require('lodash'),
Promise = require('bluebird'),
helpers = require('../../server/helpers/register'),
filters = require('../../server/filters'),
i18n = require('../../server/i18n'),
helpers = require('../../../server/helpers/register'),
filters = require('../../../server/filters'),
i18n = require('../../../server/i18n'),

// Stuff we are testing
AppProxy = require('../../server/apps/proxy'),
AppSandbox = require('../../server/apps/sandbox'),
AppDependencies = require('../../server/apps/dependencies'),
AppPermissions = require('../../server/apps/permissions'),
AppProxy = require('../../../server/services/apps/proxy'),
AppSandbox = require('../../../server/services/apps/sandbox'),
AppDependencies = require('../../../server/services/apps/dependencies'),
AppPermissions = require('../../../server/services/apps/permissions'),

sandbox = sinon.sandbox.create();

Expand Down Expand Up @@ -274,9 +274,13 @@ describe('Apps', function () {
});

describe('Sandbox', function () {
function makeAppPath(fileName) {
return path.resolve(__dirname, '..', '..', 'utils', 'fixtures', 'app', fileName);
}

it('loads apps in a sandbox', function () {
var appBox = new AppSandbox(),
appPath = path.resolve(__dirname, '..', 'utils', 'fixtures', 'app', 'good.js'),
appPath = makeAppPath('good.js'),
GoodApp,
appProxy = new AppProxy({
name: 'TestApp',
Expand All @@ -300,7 +304,7 @@ describe('Apps', function () {

it('does not allow apps to require blacklisted modules at top level', function () {
var appBox = new AppSandbox(),
badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badtop.js'),
badAppPath = makeAppPath('badtop.js'),
loadApp = function () {
appBox.loadApp(badAppPath);
};
Expand All @@ -310,7 +314,7 @@ describe('Apps', function () {

it('does not allow apps to require blacklisted modules at install', function () {
var appBox = new AppSandbox(),
badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badinstall.js'),
badAppPath = makeAppPath('badinstall.js'),
BadApp,
appProxy = new AppProxy({
name: 'TestApp',
Expand All @@ -330,7 +334,7 @@ describe('Apps', function () {

it('does not allow apps to require blacklisted modules from other requires', function () {
var appBox = new AppSandbox(),
badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badrequire.js'),
badAppPath = makeAppPath('badrequire.js'),
BadApp,
loadApp = function () {
BadApp = appBox.loadApp(badAppPath);
Expand All @@ -341,7 +345,7 @@ describe('Apps', function () {

it('does not allow apps to require modules relatively outside their directory', function () {
var appBox = new AppSandbox(),
badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badoutside.js'),
badAppPath = makeAppPath('badoutside.js'),
BadApp,
loadApp = function () {
BadApp = appBox.loadApp(badAppPath);
Expand All @@ -352,7 +356,7 @@ describe('Apps', function () {

it('does allow INTERNAL apps to require modules relatively outside their directory', function () {
var appBox = new AppSandbox({internal: true}),
badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badoutside.js'),
badAppPath = makeAppPath('badoutside.js'),
InternalApp,
loadApp = function () {
InternalApp = appBox.loadApp(badAppPath);
Expand Down

0 comments on commit b48c5e8

Please sign in to comment.