From becc239de134ab7ed628b89b9128a14f508bebd0 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 21 Apr 2020 18:08:29 +0100 Subject: [PATCH] Moved web/parent-app to web/parent/app - Have a consistent structure so we can co-locate an app with its own middleware - This is another small step in sorting out the giant mess that was web/shared/middleware --- core/server/index.js | 2 +- core/server/web/{parent-app.js => parent/app.js} | 14 +++++++------- test/regression/site/site_spec.js | 2 +- .../{parent-app_spec.js => parent/app_spec.js} | 16 ++++++---------- 4 files changed, 15 insertions(+), 19 deletions(-) rename core/server/web/{parent-app.js => parent/app.js} (85%) rename test/unit/web/{parent-app_spec.js => parent/app_spec.js} (89%) diff --git a/core/server/index.js b/core/server/index.js index 10587fdf7b..a134bf4290 100644 --- a/core/server/index.js +++ b/core/server/index.js @@ -103,7 +103,7 @@ const minimalRequiredSetupToStartGhost = (dbState) => { .then(() => { debug('Themes done'); - parentApp = require('./web/parent-app')(); + parentApp = require('./web/parent/app')(); debug('Express Apps done'); return new GhostServer(parentApp); diff --git a/core/server/web/parent-app.js b/core/server/web/parent/app.js similarity index 85% rename from core/server/web/parent-app.js rename to core/server/web/parent/app.js index 233b2f623a..a9a1b71f40 100644 --- a/core/server/web/parent-app.js +++ b/core/server/web/parent/app.js @@ -1,13 +1,13 @@ const debug = require('ghost-ignition').debug('web:parent'); const express = require('express'); const vhost = require('@tryghost/vhost-middleware'); -const config = require('../config'); +const config = require('../../config'); const compress = require('compression'); const netjet = require('netjet'); -const shared = require('./shared'); +const shared = require('../shared'); const escapeRegExp = require('lodash.escaperegexp'); const {URL} = require('url'); -const sentry = require('../sentry'); +const sentry = require('../../sentry'); module.exports = function setupParentApp(options = {}) { debug('ParentApp setup start'); @@ -53,9 +53,9 @@ module.exports = function setupParentApp(options = {}) { const adminApp = express(); adminApp.use(sentry.requestHandler); adminApp.enable('trust proxy'); // required to respect x-forwarded-proto in admin requests - adminApp.use('/ghost/api', require('./api')()); - adminApp.use('/ghost/.well-known', require('./well-known')()); - adminApp.use('/ghost', require('../services/auth/session').createSessionFromToken, require('./admin')()); + adminApp.use('/ghost/api', require('../api')()); + adminApp.use('/ghost/.well-known', require('../well-known')()); + adminApp.use('/ghost', require('../../services/auth/session').createSessionFromToken, require('../admin')()); // ADMIN + API // with a separate admin url only serve on that host, otherwise serve on all hosts @@ -67,7 +67,7 @@ module.exports = function setupParentApp(options = {}) { const frontendVhostArg = (hasSeparateAdmin && adminHost) ? new RegExp(`^(?!${escapeRegExp(adminHost)}).*`) : /.*/; - parentApp.use(vhost(frontendVhostArg, require('./site')(options))); + parentApp.use(vhost(frontendVhostArg, require('../site')(options))); debug('ParentApp setup end'); diff --git a/test/regression/site/site_spec.js b/test/regression/site/site_spec.js index ab4af61f07..083d15e9d0 100644 --- a/test/regression/site/site_spec.js +++ b/test/regression/site/site_spec.js @@ -9,7 +9,7 @@ const should = require('should'), appService = require('../../../core/frontend/services/apps'), frontendSettingsService = require('../../../core/frontend/services/settings'), themeService = require('../../../core/frontend/services/themes'), - siteApp = require('../../../core/server/web/parent-app'); + siteApp = require('../../../core/server/web/parent/app'); describe('Integration - Web - Site', function () { let app; diff --git a/test/unit/web/parent-app_spec.js b/test/unit/web/parent/app_spec.js similarity index 89% rename from test/unit/web/parent-app_spec.js rename to test/unit/web/parent/app_spec.js index a282429ead..bac076aa21 100644 --- a/test/unit/web/parent-app_spec.js +++ b/test/unit/web/parent/app_spec.js @@ -1,7 +1,7 @@ const should = require('should'); const sinon = require('sinon'); const proxyquire = require('proxyquire').noCallThru(); -const configUtils = require('../../utils/configUtils'); +const configUtils = require('../../../utils/configUtils'); describe('parent app', function () { let expressStub; @@ -30,17 +30,13 @@ describe('parent app', function () { gatewaySpy = sinon.spy(); authPagesSpy = sinon.spy(); - parentApp = proxyquire('../../../core/server/web/parent-app', { + parentApp = proxyquire('../../../../core/server/web/parent/app', { express: expressStub, '@tryghost/vhost-middleware': vhostSpy, - './api': apiSpy, - './admin': adminSpy, - './well-known': wellKnownSpy, - './site': siteSpy, - '../services/members': { - gateway: gatewaySpy, - authPages: authPagesSpy - } + '../api': apiSpy, + '../admin': adminSpy, + '../well-known': wellKnownSpy, + '../site': siteSpy }); configUtils.set('url', 'http://ghost.blog');