mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 07:10:11 +00:00
Fix crash when application doesn't have an api & remove last hook studio traces
This commit is contained in:
parent
55d5f4d84e
commit
911d2ac985
@ -144,19 +144,19 @@ module.exports = function (strapi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Merge API controllers with the main ones.
|
// Merge API controllers with the main ones.
|
||||||
strapi.controllers = _.merge({}, strapi.controllers, strapi.api[api.name].controllers);
|
strapi.controllers = _.merge({}, strapi.controllers, _.get(strapi.api, api.name + '.controllers'));
|
||||||
|
|
||||||
// Merge API services with the main ones.
|
// Merge API services with the main ones.
|
||||||
strapi.services = _.merge({}, strapi.services, strapi.api[api.name].services);
|
strapi.services = _.merge({}, strapi.services, _.get(strapi.api, api.name + '.services'));
|
||||||
|
|
||||||
// Merge API models with the main ones.
|
// Merge API models with the main ones.
|
||||||
strapi.models = _.merge({}, strapi.models, strapi.api[api.name].models);
|
strapi.models = _.merge({}, strapi.models, _.get(strapi.api, api.name + '.models'));
|
||||||
|
|
||||||
// Merge API policies with the main ones.
|
// Merge API policies with the main ones.
|
||||||
strapi.policies = _.merge({}, strapi.policies, strapi.api[api.name].policies);
|
strapi.policies = _.merge({}, strapi.policies, _.get(strapi.api, api.name + '.policies'));
|
||||||
|
|
||||||
// Merge API routes with the main ones.
|
// Merge API routes with the main ones.
|
||||||
strapi.config.routes = _.merge({}, strapi.config.routes, strapi.api[api.name].config.routes);
|
strapi.config.routes = _.merge({}, strapi.config.routes, _.get(strapi.api, api.name + '.config.routes'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,15 @@ module.exports = function (strapi) {
|
|||||||
_.extend(strapi.hooks, _.reduce(hooks.externalHooks, function (memo, module, identity) {
|
_.extend(strapi.hooks, _.reduce(hooks.externalHooks, function (memo, module, identity) {
|
||||||
if (module['package.json'] && module['package.json'].strapi && module['package.json'].strapi.isHook) {
|
if (module['package.json'] && module['package.json'].strapi && module['package.json'].strapi.isHook) {
|
||||||
const hookName = identity.match(/^strapi-/) ? identity.replace(/^strapi-/, '') : identity;
|
const hookName = identity.match(/^strapi-/) ? identity.replace(/^strapi-/, '') : identity;
|
||||||
memo[hookName] = require(path.resolve(strapi.config.appPath, 'node_modules', identity));
|
try {
|
||||||
|
memo[hookName] = require(identity);
|
||||||
|
} catch (err) {
|
||||||
|
try {
|
||||||
|
memo[hookName] = require(path.resolve(strapi.config.appPath, 'node_modules', identity));
|
||||||
|
} catch (err) {
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return memo;
|
return memo;
|
||||||
}, {}));
|
}, {}));
|
||||||
|
|||||||
@ -42,7 +42,6 @@ module.exports = function (strapi) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
initialize: function (cb) {
|
initialize: function (cb) {
|
||||||
|
|
||||||
// Middleware used for every routes.
|
// Middleware used for every routes.
|
||||||
// Expose the endpoint in `this`.
|
// Expose the endpoint in `this`.
|
||||||
function globalPolicy(endpoint, value, route) {
|
function globalPolicy(endpoint, value, route) {
|
||||||
|
|||||||
@ -120,19 +120,9 @@ module.exports = function (strapi) {
|
|||||||
loadHook('_hooks', cb);
|
loadHook('_hooks', cb);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Load the studio hook.
|
|
||||||
studio: function loadStudioHook(cb) {
|
|
||||||
if (!hooks.studio) {
|
|
||||||
return cb();
|
|
||||||
}
|
|
||||||
prepareHook('studio');
|
|
||||||
applyDefaults(hooks.studio);
|
|
||||||
loadHook('studio', cb);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Prepare all other hooks.
|
// Prepare all other hooks.
|
||||||
prepare: function prepareHooks(cb) {
|
prepare: function prepareHooks(cb) {
|
||||||
async.each(_.without(_.keys(hooks), '_config', '_api', '_hooks', 'studio', 'router'), function (id, cb) {
|
async.each(_.without(_.keys(hooks), '_config', '_api', '_hooks', 'router'), function (id, cb) {
|
||||||
prepareHook(id);
|
prepareHook(id);
|
||||||
process.nextTick(cb);
|
process.nextTick(cb);
|
||||||
}, cb);
|
}, cb);
|
||||||
@ -140,7 +130,7 @@ module.exports = function (strapi) {
|
|||||||
|
|
||||||
// Apply the default config for all other hooks.
|
// Apply the default config for all other hooks.
|
||||||
defaults: function defaultConfigHooks(cb) {
|
defaults: function defaultConfigHooks(cb) {
|
||||||
async.each(_.without(_.keys(hooks), '_config', '_api', '_hooks', 'studio', 'router'), function (id, cb) {
|
async.each(_.without(_.keys(hooks), '_config', '_api', '_hooks', 'router'), function (id, cb) {
|
||||||
const hook = hooks[id];
|
const hook = hooks[id];
|
||||||
applyDefaults(hook);
|
applyDefaults(hook);
|
||||||
process.nextTick(cb);
|
process.nextTick(cb);
|
||||||
@ -149,7 +139,7 @@ module.exports = function (strapi) {
|
|||||||
|
|
||||||
// Load all other hooks.
|
// Load all other hooks.
|
||||||
load: function loadOtherHooks(cb) {
|
load: function loadOtherHooks(cb) {
|
||||||
async.each(_.without(_.keys(hooks), '_config', '_api', '_hooks', 'studio', 'router'), function (id, cb) {
|
async.each(_.without(_.keys(hooks), '_config', '_api', '_hooks', 'router'), function (id, cb) {
|
||||||
loadHook(id, cb);
|
loadHook(id, cb);
|
||||||
}, cb);
|
}, cb);
|
||||||
},
|
},
|
||||||
@ -159,6 +149,7 @@ module.exports = function (strapi) {
|
|||||||
if (!hooks.router) {
|
if (!hooks.router) {
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareHook('router');
|
prepareHook('router');
|
||||||
applyDefaults(hooks.router);
|
applyDefaults(hooks.router);
|
||||||
loadHook('router', cb);
|
loadHook('router', cb);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user