Ghost/core/server/blog/routes.js
Katharina Irrgang 16f5d1fdaf 🎨 add urlFor('admin') and increase usage of urlFor helper (#7935)
refs #7488

- to be able to refactor the url configuration in ghost, we need to go step by step making this possible
- reduce the usage of forceAdminSSL
- add a urlFor('admin') helper, which returns the admin url + path e.g. http://my-blog.com/blog/ghost
- increase usage of urlFor helper
- do not expose getBaseUrl, use urlFor('home') (home === blog)
2017-02-02 18:51:35 +00:00

49 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(),
routeKeywords = config.get('routeKeywords');
// ### Admin routes
router.get(/^\/(logout|signout)\/$/, function redirectToSignout(req, res) {
utils.redirect301(res, utils.url.urlJoin(utils.url.urlFor('admin'), 'signout/'));
});
router.get(/^\/signup\/$/, function redirectToSignup(req, res) {
utils.redirect301(res, utils.url.urlJoin(utils.url.urlFor('admin'), '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, utils.url.urlFor('admin'));
});
// Post Live Preview
router.get(utils.url.urlJoin('/', 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.get('internalApps').forEach(function (appName) {
var app = require(path.join(config.get('paths').internalAppPath, appName));
if (app.hasOwnProperty('setupRoutes')) {
app.setupRoutes(router);
}
});
// Default
router.get('*', frontend.single);
return router;
};
module.exports = frontendRoutes;