0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/core/server/services/route/site-router.js
Hannah Wolfe 27b4688cea Changed channelsRouter to use new base class
refs #9192, #5091

- changed channels to use our new base class
- keep the flexible structure, so that channels can be reloaded
- I had to move the router into the route service otherwise we get circular dependencies
- Don't _really_ want to keep it like this - need a way to define base classes as shared
2017-11-09 10:47:20 +00:00

48 lines
1.8 KiB
JavaScript

var Router = require('./base/Router'),
siteRouter = new Router('site'),
// Sub Routers
appRouter = require('./app-router'),
channelsRouter = require('./channels-router'),
// Controllers
controllers = require('../../controllers'),
// Utils for creating paths
// @TODO: refactor these away
config = require('../../config'),
utils = require('../../utils'),
_private = {};
_private.mountDefaultRoutes = function mountDefaultRoutes() {
// @TODO move this path out of this file!
// Note this also exists in api/index.js
var previewRoute = utils.url.urlJoin('/', config.get('routeKeywords').preview, ':uuid', ':options?');
// Preview - register controller as route
// Ideal version, as we don't want these paths all over the place
// previewRoute = new Route('GET /:t_preview/:uuid/:options?', previewController);
// siteRouter.mountRoute(previewRoute);
// Orrrrr maybe preview should be an internal App??!
siteRouter.mountRoute(previewRoute, controllers.preview);
// Channels - register sub-router
// The purpose of having a parentRouter for channels, is so that we can load channels from wherever we want:
// config, settings, apps, etc, and that it will be possible for the router to be reloaded.
siteRouter.mountRouter(channelsRouter.router());
// Apps - register sub-router
// The purpose of having a parentRouter for apps, is that Apps can register a route whenever they want.
// Apps cannot yet deregister, it's complex to implement and I don't yet have a clear use-case for this.
siteRouter.mountRouter(appRouter.router());
// Default - register entry controller as route
siteRouter.mountRoute('*', controllers.entry);
};
module.exports = function router() {
_private.mountDefaultRoutes();
return siteRouter.router();
};