2017-08-17 11:52:58 +01:00
|
|
|
var express = require('express'),
|
|
|
|
path = require('path'),
|
|
|
|
config = require('../config'),
|
2017-10-09 12:56:44 +01:00
|
|
|
controllers = require('../controllers'),
|
2017-10-25 16:22:46 +01:00
|
|
|
channels = require('../controllers/channels'),
|
2017-08-17 11:52:58 +01:00
|
|
|
utils = require('../utils');
|
|
|
|
|
2017-10-26 17:24:08 +01:00
|
|
|
module.exports = function siteRouter() {
|
2014-04-11 23:46:15 -04:00
|
|
|
var router = express.Router(),
|
2016-09-13 17:41:14 +02:00
|
|
|
routeKeywords = config.get('routeKeywords');
|
2013-12-30 02:03:29 -05:00
|
|
|
|
2015-12-10 15:00:02 +00:00
|
|
|
// ### Admin routes
|
2017-10-12 13:36:50 +01:00
|
|
|
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/'); });
|
2014-09-16 21:02:31 +00:00
|
|
|
// redirect to /ghost and let that do the authentication to prevent redirects to /ghost//admin etc.
|
2017-10-12 13:36:50 +01:00
|
|
|
router.get(/^\/((ghost-admin|admin|wp-admin|dashboard|signin|login)\/?)$/, function (req, res) { return utils.url.redirectToAdmin(301, res, '/'); });
|
2014-09-16 21:02:31 +00:00
|
|
|
|
2016-02-09 14:14:24 +00:00
|
|
|
// Post Live Preview
|
2017-10-09 12:56:44 +01:00
|
|
|
router.get(utils.url.urlJoin('/', routeKeywords.preview, ':uuid', ':options?'), controllers.preview);
|
2015-05-26 14:01:52 +01:00
|
|
|
|
2016-02-09 14:14:24 +00:00
|
|
|
// Channels
|
|
|
|
router.use(channels.router());
|
2014-07-20 17:32:14 +01:00
|
|
|
|
2016-04-14 18:32:43 +01:00
|
|
|
// setup routes for internal apps
|
|
|
|
// @TODO: refactor this to be a proper app route hook for internal & external apps
|
2017-05-29 21:48:42 +02:00
|
|
|
config.get('apps:internal').forEach(function (appName) {
|
2016-09-13 17:41:14 +02:00
|
|
|
var app = require(path.join(config.get('paths').internalAppPath, appName));
|
2016-04-14 18:32:43 +01:00
|
|
|
if (app.hasOwnProperty('setupRoutes')) {
|
|
|
|
app.setupRoutes(router);
|
|
|
|
}
|
|
|
|
});
|
2016-04-11 08:58:41 -05:00
|
|
|
|
2016-08-10 12:11:41 +02:00
|
|
|
// Default
|
2017-10-09 12:56:44 +01:00
|
|
|
router.get('*', controllers.single);
|
2016-08-10 12:11:41 +02:00
|
|
|
|
2014-04-11 23:46:15 -04:00
|
|
|
return router;
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 13:41:19 +01:00
|
|
|
};
|