mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-03 00:15:11 +03:00
Decoupled routing service and theme service
- This is a fairly temporary state - It at least removes the themeService require from inside the routingService - Requires us to pass the routingService the desired API Version... - We're working towards having the entire frontend respect the theme API version by having it passed around everywhere
This commit is contained in:
parent
ca61e245e8
commit
9a2719ac4f
6
core/frontend/services/routing/bootstrap.js
vendored
6
core/frontend/services/routing/bootstrap.js
vendored
@ -2,7 +2,6 @@ const debug = require('ghost-ignition').debug('services:routing:bootstrap');
|
||||
const _ = require('lodash');
|
||||
const common = require('../../../server/lib/common');
|
||||
const settingsService = require('../settings');
|
||||
const themeService = require('../themes');
|
||||
const StaticRoutesRouter = require('./StaticRoutesRouter');
|
||||
const StaticPagesRouter = require('./StaticPagesRouter');
|
||||
const CollectionRouter = require('./CollectionRouter');
|
||||
@ -38,7 +37,7 @@ module.exports.init = (options = {start: false}) => {
|
||||
registry.setRouter('siteRouter', siteRouter);
|
||||
|
||||
if (options.start) {
|
||||
this.start();
|
||||
this.start(options.start);
|
||||
}
|
||||
|
||||
return siteRouter.router();
|
||||
@ -57,8 +56,7 @@ module.exports.init = (options = {start: false}) => {
|
||||
* 5. Static Pages: Weaker than collections, because we first try to find a post slug and fallback to lookup a static page.
|
||||
* 6. Apps: Weakest
|
||||
*/
|
||||
module.exports.start = () => {
|
||||
const apiVersion = themeService.getApiVersion();
|
||||
module.exports.start = (apiVersion) => {
|
||||
const RESOURCE_CONFIG = require(`./config/${apiVersion}`);
|
||||
|
||||
const previewRouter = new PreviewRouter(RESOURCE_CONFIG);
|
||||
|
@ -17,12 +17,17 @@ const migrator = require('./data/db/migrator');
|
||||
const urlUtils = require('./lib/url-utils');
|
||||
let parentApp;
|
||||
|
||||
// Frontend Components
|
||||
const themeService = require('../frontend/services/themes');
|
||||
|
||||
function initialiseServices() {
|
||||
// CASE: When Ghost is ready with bootstrapping (db migrations etc.), we can trigger the router creation.
|
||||
// Reason is that the routers access the routes.yaml, which shouldn't and doesn't have to be validated to
|
||||
// start Ghost in maintenance mode.
|
||||
// Routing is a bridge between the frontend and API
|
||||
const routing = require('../frontend/services/routing');
|
||||
routing.bootstrap.start();
|
||||
// We pass the themeService API version here, so that the frontend services are less tightly-coupled
|
||||
routing.bootstrap.start(themeService.getApiVersion());
|
||||
|
||||
const permissions = require('./services/permissions'),
|
||||
apps = require('./services/apps'),
|
||||
@ -73,10 +78,11 @@ function initialiseServices() {
|
||||
const minimalRequiredSetupToStartGhost = (dbState) => {
|
||||
const settings = require('./services/settings');
|
||||
const models = require('./models');
|
||||
const frontendSettings = require('../frontend/services/settings');
|
||||
const themes = require('../frontend/services/themes');
|
||||
const GhostServer = require('./ghost-server');
|
||||
|
||||
// Frontend
|
||||
const frontendSettings = require('../frontend/services/settings');
|
||||
|
||||
let ghostServer;
|
||||
|
||||
// Initialize Ghost core internationalization
|
||||
@ -94,7 +100,7 @@ const minimalRequiredSetupToStartGhost = (dbState) => {
|
||||
})
|
||||
.then(() => {
|
||||
debug('Frontend settings done');
|
||||
return themes.init();
|
||||
return themeService.init();
|
||||
})
|
||||
.then(() => {
|
||||
debug('Themes done');
|
||||
|
@ -14,7 +14,8 @@ const urlService = require('../../../frontend/services/url');
|
||||
const labsService = require('../../services/labs');
|
||||
const urlUtils = require('../../lib/url-utils');
|
||||
const sitemapHandler = require('../../../frontend/services/sitemap/handler');
|
||||
const themeMiddleware = require('../../../frontend/services/themes').middleware;
|
||||
const themeService = require('../../../frontend/services/themes');
|
||||
const themeMiddleware = themeService.middleware;
|
||||
const membersService = require('../../services/members');
|
||||
const siteRoutes = require('./routes');
|
||||
const shared = require('../shared');
|
||||
@ -260,7 +261,7 @@ module.exports = function setupSiteApp(options = {}) {
|
||||
|
||||
module.exports.reload = () => {
|
||||
// https://github.com/expressjs/express/issues/2596
|
||||
router = siteRoutes({start: true});
|
||||
router = siteRoutes({start: themeService.getApiVersion()});
|
||||
Object.setPrototypeOf(SiteRouter, router);
|
||||
|
||||
// re-initialse apps (register app routers, because we have re-initialised the site routers)
|
||||
|
Loading…
Reference in New Issue
Block a user