2016-04-11 16:58:41 +03:00
|
|
|
var config = require('../../config'),
|
2016-09-12 14:53:04 +03:00
|
|
|
utils = require('../../utils'),
|
2016-10-06 15:27:35 +03:00
|
|
|
errors = require('../../errors'),
|
2016-10-04 18:33:43 +03:00
|
|
|
logging = require('../../logging'),
|
2016-04-11 16:58:41 +03:00
|
|
|
i18n = require('../../i18n'),
|
|
|
|
middleware = require('./lib/middleware'),
|
2016-10-04 20:09:18 +03:00
|
|
|
router = require('./lib/router'),
|
|
|
|
registerHelpers = require('./lib/helpers');
|
2016-04-11 16:58:41 +03:00
|
|
|
|
|
|
|
module.exports = {
|
2016-10-04 20:09:18 +03:00
|
|
|
activate: function activate(ghost) {
|
2016-10-06 15:27:35 +03:00
|
|
|
var paths;
|
2016-10-04 18:33:43 +03:00
|
|
|
|
2016-09-12 14:53:04 +03:00
|
|
|
if (utils.url.getSubdir()) {
|
2016-10-04 18:33:43 +03:00
|
|
|
paths = utils.url.getSubdir().split('/');
|
2016-04-11 16:58:41 +03:00
|
|
|
|
2016-09-13 18:41:14 +03:00
|
|
|
if (paths.pop() === config.get('routeKeywords').private) {
|
2016-10-06 15:27:35 +03:00
|
|
|
logging.error(new errors.GhostError({
|
|
|
|
message: i18n.t('errors.config.urlCannotContainPrivateSubdir.error'),
|
|
|
|
context: i18n.t('errors.config.urlCannotContainPrivateSubdir.description'),
|
|
|
|
help: i18n.t('errors.config.urlCannotContainPrivateSubdir.help')
|
|
|
|
}));
|
2016-10-04 18:33:43 +03:00
|
|
|
|
2016-10-06 15:27:35 +03:00
|
|
|
// @TODO: why
|
2016-10-04 18:33:43 +03:00
|
|
|
process.exit(0);
|
2016-04-11 16:58:41 +03:00
|
|
|
}
|
|
|
|
}
|
2016-10-04 20:09:18 +03:00
|
|
|
|
|
|
|
registerHelpers(ghost);
|
2016-04-11 16:58:41 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
setupMiddleware: function setupMiddleware(blogApp) {
|
|
|
|
blogApp.use(middleware.checkIsPrivate);
|
|
|
|
blogApp.use(middleware.filterPrivateRoutes);
|
|
|
|
},
|
|
|
|
|
|
|
|
setupRoutes: function setupRoutes(blogRouter) {
|
2016-09-13 18:41:14 +03:00
|
|
|
blogRouter.use('/' + config.get('routeKeywords').private + '/', router);
|
2016-04-11 16:58:41 +03:00
|
|
|
}
|
|
|
|
};
|