2014-03-24 01:49:43 +04:00
|
|
|
var frontend = require('../controllers/frontend'),
|
|
|
|
config = require('../config'),
|
2014-04-12 07:46:15 +04:00
|
|
|
express = require('express'),
|
2014-07-28 17:19:49 +04:00
|
|
|
utils = require('../utils'),
|
2013-12-30 11:03:29 +04:00
|
|
|
|
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 16:41:19 +04:00
|
|
|
frontendRoutes;
|
|
|
|
|
2015-05-30 23:18:26 +03:00
|
|
|
frontendRoutes = function frontendRoutes(middleware) {
|
2014-04-12 07:46:15 +04:00
|
|
|
var router = express.Router(),
|
2015-04-16 22:40:32 +03:00
|
|
|
subdir = config.paths.subdir,
|
2015-05-26 16:01:52 +03:00
|
|
|
routeKeywords = config.routeKeywords,
|
|
|
|
indexRouter = express.Router(),
|
|
|
|
tagRouter = express.Router({mergeParams: true}),
|
|
|
|
authorRouter = express.Router({mergeParams: true}),
|
|
|
|
rssRouter = express.Router({mergeParams: true}),
|
|
|
|
privateRouter = express.Router();
|
2013-12-30 11:03:29 +04:00
|
|
|
|
2014-09-17 01:02:31 +04:00
|
|
|
// ### Admin routes
|
2015-05-30 23:18:26 +03:00
|
|
|
router.get(/^\/(logout|signout)\/$/, function redirectToSignout(req, res) {
|
2014-09-17 01:02:31 +04:00
|
|
|
/*jslint unparam:true*/
|
|
|
|
res.set({'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S});
|
|
|
|
res.redirect(301, subdir + '/ghost/signout/');
|
|
|
|
});
|
2015-05-30 23:18:26 +03:00
|
|
|
router.get(/^\/signup\/$/, function redirectToSignup(req, res) {
|
2014-09-17 01:02:31 +04:00
|
|
|
/*jslint unparam:true*/
|
|
|
|
res.set({'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S});
|
|
|
|
res.redirect(301, subdir + '/ghost/signup/');
|
|
|
|
});
|
|
|
|
|
|
|
|
// redirect to /ghost and let that do the authentication to prevent redirects to /ghost//admin etc.
|
2015-05-30 23:18:26 +03:00
|
|
|
router.get(/^\/((ghost-admin|admin|wp-admin|dashboard|signin|login)\/?)$/, function redirectToAdmin(req, res) {
|
2014-09-17 01:02:31 +04:00
|
|
|
/*jslint unparam:true*/
|
|
|
|
res.redirect(subdir + '/ghost/');
|
|
|
|
});
|
|
|
|
|
2015-03-26 10:01:39 +03:00
|
|
|
// password-protected frontend route
|
2015-05-26 16:01:52 +03:00
|
|
|
privateRouter.route('/')
|
|
|
|
.get(
|
2015-07-15 19:01:23 +03:00
|
|
|
middleware.privateBlogging.isPrivateSessionAuth,
|
2015-05-26 16:01:52 +03:00
|
|
|
frontend.private
|
|
|
|
)
|
|
|
|
.post(
|
2015-07-15 19:01:23 +03:00
|
|
|
middleware.privateBlogging.isPrivateSessionAuth,
|
2015-05-26 22:04:27 +03:00
|
|
|
middleware.spamPrevention.protected,
|
2015-07-15 19:01:23 +03:00
|
|
|
middleware.privateBlogging.authenticateProtection,
|
2015-05-26 16:01:52 +03:00
|
|
|
frontend.private
|
|
|
|
);
|
2015-03-26 10:01:39 +03:00
|
|
|
|
2015-05-26 16:01:52 +03:00
|
|
|
rssRouter.route('/rss/').get(frontend.rss);
|
|
|
|
rssRouter.route('/rss/:page/').get(frontend.rss);
|
|
|
|
rssRouter.route('/feed/').get(function redirect(req, res) {
|
2014-03-24 01:49:43 +04:00
|
|
|
/*jshint unused:true*/
|
2014-07-28 17:19:49 +04:00
|
|
|
res.set({'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S});
|
2014-03-24 01:49:43 +04:00
|
|
|
res.redirect(301, subdir + '/rss/');
|
|
|
|
});
|
|
|
|
|
2015-05-26 16:01:52 +03:00
|
|
|
// Index
|
|
|
|
indexRouter.route('/').get(frontend.homepage);
|
|
|
|
indexRouter.route('/' + routeKeywords.page + '/:page/').get(frontend.homepage);
|
|
|
|
indexRouter.use(rssRouter);
|
|
|
|
|
2014-07-20 20:32:14 +04:00
|
|
|
// Tags
|
2015-05-26 16:01:52 +03:00
|
|
|
tagRouter.route('/').get(frontend.tag);
|
|
|
|
tagRouter.route('/' + routeKeywords.page + '/:page/').get(frontend.tag);
|
|
|
|
tagRouter.use(rssRouter);
|
2014-07-20 20:32:14 +04:00
|
|
|
|
|
|
|
// Authors
|
2015-05-26 16:01:52 +03:00
|
|
|
authorRouter.route('/').get(frontend.author);
|
|
|
|
authorRouter.route('/' + routeKeywords.page + '/:page/').get(frontend.author);
|
|
|
|
authorRouter.use(rssRouter);
|
|
|
|
|
|
|
|
// Mount the Routers
|
|
|
|
router.use('/' + routeKeywords.private + '/', privateRouter);
|
|
|
|
router.use('/' + routeKeywords.author + '/:slug/', authorRouter);
|
|
|
|
router.use('/' + routeKeywords.tag + '/:slug/', tagRouter);
|
|
|
|
router.use('/', indexRouter);
|
2015-04-16 22:40:32 +03:00
|
|
|
|
|
|
|
// Post Live Preview
|
|
|
|
router.get('/' + routeKeywords.preview + '/:uuid', frontend.preview);
|
2014-07-20 20:32:14 +04:00
|
|
|
|
|
|
|
// Default
|
2014-04-12 07:46:15 +04:00
|
|
|
router.get('*', frontend.single);
|
|
|
|
|
|
|
|
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 16:41:19 +04:00
|
|
|
};
|
2014-03-24 01:49:43 +04:00
|
|
|
|
2014-09-10 08:06:24 +04:00
|
|
|
module.exports = frontendRoutes;
|