2021-10-04 18:50:07 +03:00
|
|
|
const path = require('path');
|
2021-09-26 22:21:49 +03:00
|
|
|
const tpl = require('@tryghost/tpl');
|
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');
|
2021-09-26 22:21:49 +03:00
|
|
|
const urlUtils = require('../../../shared/url-utils');
|
2020-04-29 18:44:27 +03:00
|
|
|
const middleware = require('./lib/middleware');
|
|
|
|
const router = require('./lib/router');
|
|
|
|
|
2021-09-26 22:21:49 +03:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-29 18:44:27 +03:00
|
|
|
// 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) {
|
2021-12-01 13:22:01 +03:00
|
|
|
logging.error(new errors.InternalServerError({
|
2021-09-26 22:21:49 +03:00
|
|
|
message: tpl(messages.urlCannotContainPrivateSubdir.error),
|
|
|
|
context: tpl(messages.urlCannotContainPrivateSubdir.description),
|
|
|
|
help: tpl(messages.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);
|
2021-10-04 18:50:07 +03:00
|
|
|
ghost.helperService.registerDir(path.resolve(__dirname, './lib/helpers'));
|
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
|
|
|
}
|
|
|
|
};
|