2019-06-19 12:30:28 +03:00
|
|
|
const urlUtils = require('../../../server/lib/url-utils'),
|
|
|
|
common = require('../../../server/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'),
|
2018-04-17 12:36:05 +03:00
|
|
|
// routeKeywords.private: 'private'
|
2018-06-28 11:50:03 +03:00
|
|
|
PRIVATE_KEYWORD = 'private';
|
2016-04-11 16:58:41 +03:00
|
|
|
|
2018-06-28 11:50:03 +03:00
|
|
|
let checkSubdir = function checkSubdir() {
|
|
|
|
let paths = '';
|
2016-10-04 18:33:43 +03:00
|
|
|
|
2019-06-18 16:13:55 +03:00
|
|
|
if (urlUtils.getSubdir()) {
|
|
|
|
paths = urlUtils.getSubdir().split('/');
|
2016-04-11 16:58:41 +03:00
|
|
|
|
2018-04-17 12:36:05 +03:00
|
|
|
if (paths.pop() === PRIVATE_KEYWORD) {
|
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) {
|
2018-06-28 11:50:03 +03:00
|
|
|
let privateRoute = `/${PRIVATE_KEYWORD}/`;
|
2017-11-05 15:45:43 +03:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|