2020-11-25 15:33:44 +03:00
|
|
|
const {i18n} = require('../../services/proxy');
|
2020-05-28 13:57:02 +03:00
|
|
|
const urlUtils = require('../../../shared/url-utils');
|
2021-06-15 17:36:27 +03:00
|
|
|
const logging = require('@tryghost/logging');
|
2020-05-22 21:22:20 +03:00
|
|
|
const errors = require('@tryghost/errors');
|
2020-04-29 18:44:27 +03:00
|
|
|
const middleware = require('./lib/middleware');
|
|
|
|
const router = require('./lib/router');
|
|
|
|
const registerHelpers = require('./lib/helpers');
|
|
|
|
|
|
|
|
// routeKeywords.private: 'private'
|
|
|
|
const 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) {
|
2020-05-22 21:22:20 +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')
|
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);
|
2020-06-16 13:42:32 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
setupErrorHandling: function setupErrorHandling(siteApp) {
|
|
|
|
siteApp.use(middleware.handle404);
|
2016-04-11 16:58:41 +03:00
|
|
|
}
|
|
|
|
};
|