Ghost/core/frontend/apps/private-blogging/index.js
Vikas Potluri 00c324fa4e
Moved core/server/lib/common/logging to core/shared/logging (#11857)
- Represents that logging is shared across all parts of Ghost at present
  * moved core/server/lib/common/logging to core/shared/logging
  * updated logging path for generic imports
  * updated migration and schema imports of logging
  * updated tests and index logging import
  * 🔥 removed logging from common module
  * fixed tests
2020-05-28 19:30:23 +01:00

47 lines
1.4 KiB
JavaScript

const {i18n} = require('../../../server/lib/common');
const urlUtils = require('../../../shared/url-utils');
const logging = require('../../../shared/logging');
const errors = require('@tryghost/errors');
const middleware = require('./lib/middleware');
const router = require('./lib/router');
const registerHelpers = require('./lib/helpers');
// routeKeywords.private: 'private'
const PRIVATE_KEYWORD = 'private';
let checkSubdir = function checkSubdir() {
let paths = '';
if (urlUtils.getSubdir()) {
paths = urlUtils.getSubdir().split('/');
if (paths.pop() === PRIVATE_KEYWORD) {
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')
}));
// @TODO: why
process.exit(0);
}
}
};
module.exports = {
activate: function activate(ghost) {
let privateRoute = `/${PRIVATE_KEYWORD}/`;
checkSubdir();
ghost.routeService.registerRouter(privateRoute, router);
registerHelpers(ghost);
},
setupMiddleware: function setupMiddleware(siteApp) {
siteApp.use(middleware.checkIsPrivate);
siteApp.use(middleware.filterPrivateRoutes);
}
};