0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/core/server/site/routes.js
Hannah Wolfe 9b54ed0689 Refactored apps to have access to a router
refs #9192

- Instead of `setupRoutes` function in apps that gets passed a router, there is now a registerRouter function as part of the proxy
- Moved towards a route service, which will know about all routes
- Using classes to abstract away shared behaviour

Notes:

- changing the app proxy didn't result in a test failure!
- structure of route service is totally new and may change a lot yet
2017-11-01 15:02:25 +00:00

31 lines
1.2 KiB
JavaScript

var express = require('express'),
config = require('../config'),
controllers = require('../controllers'),
channels = require('../controllers/channels'),
apps = require('../services/route').appRouter,
utils = require('../utils');
module.exports = function siteRouter() {
var router = express.Router(),
routeKeywords = config.get('routeKeywords');
// ### Admin routes
router.get(/^\/(logout|signout)\/$/, function (req, res) { return utils.url.redirectToAdmin(301, res, '#/signout/'); });
router.get(/^\/signup\/$/, function (req, res) { return utils.url.redirectToAdmin(301, res, '#/signup/'); });
// redirect to /ghost and let that do the authentication to prevent redirects to /ghost//admin etc.
router.get(/^\/((ghost-admin|admin|wp-admin|dashboard|signin|login)\/?)$/, function (req, res) { return utils.url.redirectToAdmin(301, res, '/'); });
// Post Live Preview
router.get(utils.url.urlJoin('/', routeKeywords.preview, ':uuid', ':options?'), controllers.preview);
// Channels
router.use(channels.router());
// setup routes for apps
router.use(apps.router);
// Default
router.get('*', controllers.single);
return router;
};