2017-12-11 21:14:05 +03:00
|
|
|
var config = require('../../config'),
|
|
|
|
urlService = require('../../services/url'),
|
2017-12-12 00:47:46 +03:00
|
|
|
common = require('../../lib/common'),
|
2016-04-11 16:58:41 +03:00
|
|
|
middleware = require('./lib/middleware'),
|
2017-12-11 21:14:05 +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-12-11 21:14:05 +03:00
|
|
|
if (urlService.utils.getSubdir()) {
|
|
|
|
paths = urlService.utils.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) {
|
2017-12-12 00:47:46 +03:00
|
|
|
common.logging.error(new common.errors.GhostError({
|
|
|
|
message: common.i18n.t('errors.config.urlCannotContainPrivateSubdir.error'),
|
|
|
|
context: common.i18n.t('errors.config.urlCannotContainPrivateSubdir.description'),
|
|
|
|
help: common.i18n.t('errors.config.urlCannotContainPrivateSubdir.help')
|
2017-11-05 15:45:43 +03:00
|
|
|
}));
|
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
|
|
|
}
|
|
|
|
};
|