Ghost/core/server/routes/frontend.js
Aileen Nowak 3c669cdd1f Swap order of apps & catch-all route (#7194)
no issue

This small change swaps over the order in which the app routes, and catch-all `*` routes are processed.

This will have an impact on the behaviour of all of our internal apps. Both the private blogging and subscribers apps have a route where they render their own template. Private blogging has `/private/` which renders `private.hbs` and subscribers has a similar `/subscribe/` route (and in future `/unsubscribe/`).

Because these routes weren't listed in our reserved words list, it is possible for a blog to already have a post or a page that lives at `/private/` or, perhaps more likely `/subscribe/`. Prior to this change, their already setup page would be rendered instead of the app's page. After this change, the app's own route will be correctly rendered.

This is effectively a bug fix, because if you enable these features then you would expect them to work.

Moving forward, this change is absolutely required for the AMP app, because the route for that app is `*/amp/`. If the app routes aren't processed first, then this will not work.
2016-08-10 11:11:41 +01:00

50 lines
1.7 KiB
JavaScript

var express = require('express'),
path = require('path'),
config = require('../config'),
frontend = require('../controllers/frontend'),
channels = require('../controllers/frontend/channels'),
utils = require('../utils'),
frontendRoutes;
frontendRoutes = function frontendRoutes() {
var router = express.Router(),
subdir = config.paths.subdir,
routeKeywords = config.routeKeywords;
// ### Admin routes
router.get(/^\/(logout|signout)\/$/, function redirectToSignout(req, res) {
utils.redirect301(res, subdir + '/ghost/signout/');
});
router.get(/^\/signup\/$/, function redirectToSignup(req, res) {
utils.redirect301(res, subdir + '/ghost/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 redirectToAdmin(req, res) {
utils.redirect301(res, subdir + '/ghost/');
});
// Post Live Preview
router.get('/' + routeKeywords.preview + '/:uuid', frontend.preview);
// Channels
router.use(channels.router());
// setup routes for internal apps
// @TODO: refactor this to be a proper app route hook for internal & external apps
config.internalApps.forEach(function (appName) {
var app = require(path.join(config.paths.internalAppPath, appName));
if (app.hasOwnProperty('setupRoutes')) {
app.setupRoutes(router);
}
});
// Default
router.get('*', frontend.single);
return router;
};
module.exports = frontendRoutes;