0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Renamed app related files+variables for clarity

- renamed the parentApp in index.js to ghostApp, to reduce confusion with the layer that is named parentApp
- renamed the adminApp inside of parentApp to backendApp to reflect the fact it's both admin+api
- renamed a bunch more variables there to be backend, rather than admin
- renamed the api index.js file to app.js and created a new index which is an actual index
This commit is contained in:
Hannah Wolfe 2020-04-27 16:54:31 +01:00
parent d6272eff42
commit be10039f76
4 changed files with 48 additions and 47 deletions

View file

@ -0,0 +1,31 @@
const debug = require('ghost-ignition').debug('web:api:default:app');
const express = require('express');
const urlUtils = require('../../lib/url-utils');
const errorHandler = require('../shared/middlewares/error-handler');
const sentry = require('../../sentry');
module.exports = function setupApiApp() {
debug('Parent API setup start');
const apiApp = express();
apiApp.use(sentry.requestHandler);
// Mount different API versions
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'content'}), require('./v2/content/app')());
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'admin'}), require('./v2/admin/app')());
apiApp.use(urlUtils.getVersionPath({version: 'v3', type: 'content'}), require('./canary/content/app')());
apiApp.use(urlUtils.getVersionPath({version: 'v3', type: 'admin'}), require('./canary/admin/app')());
apiApp.use(urlUtils.getVersionPath({version: 'v3', type: 'members'}), require('./canary/members/app')());
apiApp.use(urlUtils.getVersionPath({version: 'canary', type: 'content'}), require('./canary/content/app')());
apiApp.use(urlUtils.getVersionPath({version: 'canary', type: 'admin'}), require('./canary/admin/app')());
apiApp.use(urlUtils.getVersionPath({version: 'canary', type: 'members'}), require('./canary/members/app')());
// Error handling for requests to non-existent API versions
apiApp.use(sentry.errorHandler);
apiApp.use(errorHandler.resourceNotFound);
apiApp.use(errorHandler.handleJSONResponse);
debug('Parent API setup end');
return apiApp;
};

View file

@ -1,31 +1 @@
const debug = require('ghost-ignition').debug('web:api:default:app');
const express = require('express');
const urlUtils = require('../../lib/url-utils');
const errorHandler = require('../shared/middlewares/error-handler');
const sentry = require('../../sentry');
module.exports = function setupApiApp() {
debug('Parent API setup start');
const apiApp = express();
apiApp.use(sentry.requestHandler);
// Mount different API versions
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'content'}), require('./v2/content/app')());
apiApp.use(urlUtils.getVersionPath({version: 'v2', type: 'admin'}), require('./v2/admin/app')());
apiApp.use(urlUtils.getVersionPath({version: 'v3', type: 'content'}), require('./canary/content/app')());
apiApp.use(urlUtils.getVersionPath({version: 'v3', type: 'admin'}), require('./canary/admin/app')());
apiApp.use(urlUtils.getVersionPath({version: 'v3', type: 'members'}), require('./canary/members/app')());
apiApp.use(urlUtils.getVersionPath({version: 'canary', type: 'content'}), require('./canary/content/app')());
apiApp.use(urlUtils.getVersionPath({version: 'canary', type: 'admin'}), require('./canary/admin/app')());
apiApp.use(urlUtils.getVersionPath({version: 'canary', type: 'members'}), require('./canary/members/app')());
// Error handling for requests to non-existent API versions
apiApp.use(sentry.errorHandler);
apiApp.use(errorHandler.resourceNotFound);
apiApp.use(errorHandler.handleJSONResponse);
debug('Parent API setup end');
return apiApp;
};
module.exports = require('./app');

View file

@ -46,27 +46,27 @@ module.exports = function setupParentApp(options = {}) {
// Mount the express apps on the parentApp
const adminHost = config.get('admin:url') ? (new URL(config.get('admin:url')).hostname) : '';
const backendHost = config.get('admin:url') ? (new URL(config.get('admin:url')).hostname) : '';
const frontendHost = new URL(config.get('url')).hostname;
const hasSeparateAdmin = adminHost && adminHost !== frontendHost;
const hasSeparateBackendHost = backendHost && backendHost !== frontendHost;
// Wrap the admin and API apps into a single express app for use with vhost
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')());
const backendApp = express();
backendApp.use(sentry.requestHandler);
backendApp.enable('trust proxy'); // required to respect x-forwarded-proto in admin requests
backendApp.use('/ghost/api', require('../api')());
backendApp.use('/ghost/.well-known', require('../well-known')());
backendApp.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
const adminVhostArg = hasSeparateAdmin && adminHost ? adminHost : /.*/;
parentApp.use(vhost(adminVhostArg, adminApp));
const backendVhostArg = hasSeparateBackendHost && backendHost ? backendHost : /.*/;
parentApp.use(vhost(backendVhostArg, backendApp));
// BLOG
// with a separate admin url we adjust the frontend vhost to exclude requests to that host, otherwise serve on all hosts
const frontendVhostArg = (hasSeparateAdmin && adminHost) ?
new RegExp(`^(?!${escapeRegExp(adminHost)}).*`) : /.*/;
const frontendVhostArg = (hasSeparateBackendHost && backendHost) ?
new RegExp(`^(?!${escapeRegExp(backendHost)}).*`) : /.*/;
parentApp.use(vhost(frontendVhostArg, require('../site')(options)));

View file

@ -14,19 +14,19 @@ debug('Required ghost');
const express = require('express');
const common = require('./core/server/lib/common');
const urlService = require('./core/frontend/services/url');
const parentApp = express();
const ghostApp = express();
parentApp.use(sentry.requestHandler);
ghostApp.use(sentry.requestHandler);
debug('Initialising Ghost');
ghost().then(function (ghostServer) {
// Mount our Ghost instance on our desired subdirectory path if it exists.
parentApp.use(urlService.utils.getSubdir(), ghostServer.rootApp);
ghostApp.use(urlService.utils.getSubdir(), ghostServer.rootApp);
debug('Starting Ghost');
// Let Ghost handle starting our server instance.
return ghostServer.start(parentApp)
return ghostServer.start(ghostApp)
.then(function afterStart() {
common.logging.info('Ghost boot', (Date.now() - startTime) / 1000 + 's');
});