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