mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
2887e416da
refs: TryGhost/Toolbox#147 * Replaces all references to isIgnitionError with isGhostError * Switches use of GhostError to InternalServerError - as GhostError is no longer public There are places where InternalServerError is not the valid error, and new errors should be added to the @tryghost/errors package to ensure that we can use semantically correct errors in those cases.
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
const path = require('path');
|
|
const tpl = require('@tryghost/tpl');
|
|
const logging = require('@tryghost/logging');
|
|
const errors = require('@tryghost/errors');
|
|
const urlUtils = require('../../../shared/url-utils');
|
|
const middleware = require('./lib/middleware');
|
|
const router = require('./lib/router');
|
|
|
|
const messages = {
|
|
urlCannotContainPrivateSubdir: {
|
|
error: 'private subdirectory not allowed',
|
|
description: 'Your site url in config.js cannot contain a subdirectory called private.',
|
|
help: 'Please rename the subdirectory before restarting'
|
|
}
|
|
};
|
|
|
|
// 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.InternalServerError({
|
|
message: tpl(messages.urlCannotContainPrivateSubdir.error),
|
|
context: tpl(messages.urlCannotContainPrivateSubdir.description),
|
|
help: tpl(messages.urlCannotContainPrivateSubdir.help)
|
|
}));
|
|
|
|
// @TODO: why
|
|
process.exit(0);
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
activate: function activate(ghost) {
|
|
let privateRoute = `/${PRIVATE_KEYWORD}/`;
|
|
|
|
checkSubdir();
|
|
|
|
ghost.routeService.registerRouter(privateRoute, router);
|
|
ghost.helperService.registerDir(path.resolve(__dirname, './lib/helpers'));
|
|
},
|
|
|
|
setupMiddleware: function setupMiddleware(siteApp) {
|
|
siteApp.use(middleware.checkIsPrivate);
|
|
siteApp.use(middleware.filterPrivateRoutes);
|
|
},
|
|
|
|
setupErrorHandling: function setupErrorHandling(siteApp) {
|
|
siteApp.use(middleware.handle404);
|
|
}
|
|
};
|