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'),
|
2017-11-05 15:45:43 +03:00
|
|
|
registerHelpers = require('./lib/helpers'),
|
|
|
|
checkSubdir;
|
2016-04-11 16:58:41 +03:00
|
|
|
|
2017-11-05 15:45:43 +03:00
|
|
|
checkSubdir = function checkSubdir() {
|
|
|
|
var paths;
|
2016-10-04 18:33:43 +03:00
|
|
|
|
2017-11-05 15:45:43 +03:00
|
|
|
if (utils.url.getSubdir()) {
|
|
|
|
paths = utils.url.getSubdir().split('/');
|
2016-04-11 16:58:41 +03:00
|
|
|
|
2017-11-05 15:45:43 +03:00
|
|
|
if (paths.pop() === config.get('routeKeywords').private) {
|
|
|
|
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
|
|
|
|
2017-11-05 15:45:43 +03:00
|
|
|
// @TODO: why
|
|
|
|
process.exit(0);
|
2016-04-11 16:58:41 +03:00
|
|
|
}
|
2017-11-05 15:45:43 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
activate: function activate(ghost) {
|
|
|
|
var privateRoute = '/' + config.get('routeKeywords').private + '/';
|
|
|
|
|
|
|
|
checkSubdir();
|
2016-10-04 20:09:18 +03:00
|
|
|
|
2017-11-05 15:45:43 +03:00
|
|
|
ghost.routeService.registerRouter(privateRoute, router);
|
2017-10-31 12:46:59 +03:00
|
|
|
|
2016-10-04 20:09:18 +03:00
|
|
|
registerHelpers(ghost);
|
2016-04-11 16:58:41 +03:00
|
|
|
},
|
|
|
|
|
2017-10-26 19:24:08 +03:00
|
|
|
setupMiddleware: function setupMiddleware(siteApp) {
|
|
|
|
siteApp.use(middleware.checkIsPrivate);
|
|
|
|
siteApp.use(middleware.filterPrivateRoutes);
|
2016-04-11 16:58:41 +03:00
|
|
|
}
|
|
|
|
};
|