2015-10-01 00:30:16 +02:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-04 17:02:27 +02:00
|
|
|
const Koa = require('koa');
|
2019-08-21 11:05:33 +02:00
|
|
|
const Router = require('koa-router');
|
2019-04-05 16:11:09 +02:00
|
|
|
const _ = require('lodash');
|
2021-05-20 08:55:18 +02:00
|
|
|
const { createLogger } = require('@strapi/logger');
|
2021-05-10 15:36:09 +02:00
|
|
|
const { Database } = require('@strapi/database');
|
2019-10-15 16:21:59 +02:00
|
|
|
|
2021-08-03 09:12:58 +02:00
|
|
|
const loadConfiguration = require('./core/app-configuration');
|
2021-08-05 13:59:40 +02:00
|
|
|
|
2021-08-05 11:32:56 +02:00
|
|
|
const { createHTTPServer } = require('./server');
|
2021-08-05 12:24:48 +02:00
|
|
|
const { createContainer } = require('./container');
|
2021-07-08 11:20:13 +02:00
|
|
|
const loadModules = require('./core/loaders/load-modules');
|
2021-08-05 11:32:56 +02:00
|
|
|
const utils = require('./utils');
|
2021-07-08 11:20:13 +02:00
|
|
|
const bootstrap = require('./core/loaders/bootstrap');
|
|
|
|
const initializeMiddlewares = require('./middlewares');
|
2019-04-10 18:11:55 +02:00
|
|
|
const createStrapiFs = require('./core/fs');
|
2019-12-17 10:35:04 +01:00
|
|
|
const createEventHub = require('./services/event-hub');
|
2019-12-17 11:24:14 +01:00
|
|
|
const createWebhookRunner = require('./services/webhook-runner');
|
2021-07-08 11:20:13 +02:00
|
|
|
const { webhookModel, createWebhookStore } = require('./services/webhook-store');
|
|
|
|
const { createCoreStore, coreStoreModel } = require('./services/core-store');
|
2020-01-08 11:12:41 +01:00
|
|
|
const createEntityService = require('./services/entity-service');
|
2020-09-22 12:31:26 +02:00
|
|
|
const entityValidator = require('./services/entity-validator');
|
2020-03-27 15:30:03 +01:00
|
|
|
const createTelemetry = require('./services/metrics');
|
2020-11-04 18:26:26 +01:00
|
|
|
const createUpdateNotifier = require('./utils/update-notifier');
|
2021-08-03 09:12:58 +02:00
|
|
|
const createStartupLogger = require('./utils/startup-logger');
|
2020-07-01 09:43:28 +02:00
|
|
|
const ee = require('./utils/ee');
|
2021-08-05 13:59:40 +02:00
|
|
|
// const createContainer = require('./core/container');
|
2021-08-06 18:09:49 +02:00
|
|
|
// const createContainer = require('./core/container');
|
|
|
|
const contentTypesRegistry = require('./core/registries/content-types');
|
|
|
|
const servicesRegistry = require('./core/registries/services');
|
|
|
|
const policiesRegistry = require('./core/registries/policies');
|
|
|
|
const middlewaresRegistry = require('./core/registries/middlewares');
|
|
|
|
const controllersRegistry = require('./core/registries/controllers');
|
|
|
|
const modulesRegistry = require('./core/registries/modules');
|
|
|
|
const createConfigProvider = require('./core/registries/config');
|
|
|
|
const loadPlugins = require('./core/load-plugins');
|
2019-12-17 10:35:04 +01:00
|
|
|
|
2021-02-16 12:23:51 +01:00
|
|
|
const LIFECYCLES = {
|
|
|
|
REGISTER: 'register',
|
2021-02-16 15:34:10 +01:00
|
|
|
BOOTSTRAP: 'bootstrap',
|
2021-02-16 12:23:51 +01:00
|
|
|
};
|
|
|
|
|
2020-03-27 10:30:43 +01:00
|
|
|
class Strapi {
|
2020-01-10 12:25:41 +01:00
|
|
|
constructor(opts = {}) {
|
2021-08-05 11:32:56 +02:00
|
|
|
this.dir = opts.dir || process.cwd();
|
2021-08-06 18:09:49 +02:00
|
|
|
const appConfig = loadConfiguration(this.dir, opts);
|
|
|
|
this.container = createContainer(this);
|
|
|
|
this.container.register('config', createConfigProvider(appConfig));
|
|
|
|
this.container.register('content-types', contentTypesRegistry(this));
|
|
|
|
this.container.register('services', servicesRegistry(this));
|
|
|
|
this.container.register('policies', policiesRegistry(this));
|
|
|
|
this.container.register('middlewares', middlewaresRegistry(this));
|
|
|
|
this.container.register('controllers', controllersRegistry(this));
|
|
|
|
this.container.register('modules', modulesRegistry(this));
|
2021-08-05 11:32:56 +02:00
|
|
|
|
2021-08-06 18:09:49 +02:00
|
|
|
this.isLoaded = false;
|
2017-08-02 13:17:40 +02:00
|
|
|
this.reload = this.reload();
|
2016-11-04 16:00:19 +01:00
|
|
|
this.app = new Koa();
|
2019-08-21 11:05:33 +02:00
|
|
|
this.router = new Router();
|
2021-08-05 11:32:56 +02:00
|
|
|
this.server = createHTTPServer(this, this.app);
|
2021-08-06 18:09:49 +02:00
|
|
|
this.plugins = {}; // to remove V3
|
|
|
|
this.contentTypes = {}; // to remove V3
|
2019-12-17 10:35:04 +01:00
|
|
|
this.fs = createStrapiFs(this);
|
|
|
|
this.eventHub = createEventHub();
|
2021-08-03 09:12:58 +02:00
|
|
|
this.startupLogger = createStartupLogger(this);
|
2021-08-06 18:09:49 +02:00
|
|
|
this.app.proxy = this.config.get('server.proxy');
|
|
|
|
this.log = createLogger(this.config.get('logger', {}));
|
2020-10-30 17:16:09 +01:00
|
|
|
|
2020-11-04 18:26:26 +01:00
|
|
|
createUpdateNotifier(this).notify();
|
2019-12-17 10:35:04 +01:00
|
|
|
}
|
2017-07-28 18:34:13 +02:00
|
|
|
|
2021-08-06 18:09:49 +02:00
|
|
|
get config() {
|
|
|
|
return this.container.get('config');
|
|
|
|
}
|
|
|
|
|
2020-07-03 17:59:06 +02:00
|
|
|
get EE() {
|
2021-05-20 08:55:18 +02:00
|
|
|
return ee({ dir: this.dir, logger: this.log });
|
2020-07-03 17:59:06 +02:00
|
|
|
}
|
|
|
|
|
2021-08-11 10:05:20 +02:00
|
|
|
service(uid) {
|
|
|
|
return this.container.get('services').get(uid);
|
|
|
|
}
|
|
|
|
|
2021-08-06 18:09:49 +02:00
|
|
|
plugin(name) {
|
|
|
|
return this.container.get('modules').get(`plugin::${name}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
get pluginsV4() {
|
|
|
|
return this.container.get('modules').getAll('plugin::');
|
|
|
|
}
|
|
|
|
|
2021-08-09 20:13:05 +02:00
|
|
|
async start() {
|
2020-09-01 14:59:08 +02:00
|
|
|
try {
|
|
|
|
if (!this.isLoaded) {
|
|
|
|
await this.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.app.use(this.router.routes()).use(this.router.allowedMethods());
|
|
|
|
|
|
|
|
// Launch server.
|
2021-08-09 20:13:05 +02:00
|
|
|
await this.listen();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
} catch (error) {
|
2021-08-17 19:28:10 +02:00
|
|
|
return this.stopWithError(error);
|
2020-09-01 14:59:08 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-14 17:35:25 +01:00
|
|
|
|
2020-11-10 14:15:31 +01:00
|
|
|
async destroy() {
|
2021-08-09 20:13:05 +02:00
|
|
|
await this.server.destroy();
|
2020-11-25 17:22:41 +01:00
|
|
|
|
2020-12-29 17:44:14 +01:00
|
|
|
await Promise.all(
|
|
|
|
Object.values(this.plugins).map(plugin => {
|
|
|
|
if (_.has(plugin, 'destroy') && typeof plugin.destroy === 'function') {
|
|
|
|
return plugin.destroy();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2020-11-25 17:22:41 +01:00
|
|
|
|
2020-11-25 18:27:01 +01:00
|
|
|
if (_.has(this, 'admin')) {
|
|
|
|
await this.admin.destroy();
|
|
|
|
}
|
|
|
|
|
2020-11-25 17:22:41 +01:00
|
|
|
this.eventHub.removeAllListeners();
|
|
|
|
|
2020-11-30 14:23:03 +01:00
|
|
|
if (_.has(this, 'db')) {
|
|
|
|
await this.db.destroy();
|
|
|
|
}
|
|
|
|
|
2021-03-29 12:33:08 +02:00
|
|
|
this.telemetry.destroy();
|
|
|
|
|
2020-11-25 17:22:41 +01:00
|
|
|
delete global.strapi;
|
2020-11-10 14:15:31 +01:00
|
|
|
}
|
|
|
|
|
2021-08-09 20:13:05 +02:00
|
|
|
sendStartupTelemetry() {
|
|
|
|
// Get database clients
|
|
|
|
const databaseClients = _.map(this.config.get('connections'), _.property('settings.client'));
|
|
|
|
|
|
|
|
// Emit started event.
|
|
|
|
// do not await to avoid slower startup
|
|
|
|
this.telemetry.send('didStartServer', {
|
|
|
|
database: databaseClients,
|
|
|
|
plugins: this.config.installedPlugins,
|
|
|
|
providers: this.config.installedProviders,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async openAdmin({ isInitialized }) {
|
|
|
|
const shouldOpenAdmin =
|
|
|
|
this.config.environment === 'development' &&
|
|
|
|
this.config.get('server.admin.autoOpen', true) !== false;
|
|
|
|
|
|
|
|
if (shouldOpenAdmin || !isInitialized) {
|
|
|
|
await utils.openBrowser(this.config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async postListen() {
|
|
|
|
const isInitialized = await utils.isInitialized(this);
|
|
|
|
|
|
|
|
this.startupLogger.logStartupMessage({ isInitialized });
|
|
|
|
|
|
|
|
this.sendStartupTelemetry();
|
|
|
|
this.openAdmin({ isInitialized });
|
|
|
|
}
|
|
|
|
|
2020-09-01 14:59:08 +02:00
|
|
|
/**
|
|
|
|
* Add behaviors to the server
|
|
|
|
*/
|
2021-08-09 20:13:05 +02:00
|
|
|
async listen() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const onListen = async error => {
|
|
|
|
if (error) {
|
|
|
|
return reject(error);
|
2020-07-16 09:01:08 +02:00
|
|
|
}
|
2021-04-19 14:44:35 +02:00
|
|
|
|
2021-08-09 20:13:05 +02:00
|
|
|
try {
|
|
|
|
await this.postListen();
|
2020-03-14 17:35:25 +01:00
|
|
|
|
2021-08-09 20:13:05 +02:00
|
|
|
resolve();
|
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
};
|
2020-03-14 17:35:25 +01:00
|
|
|
|
2021-08-09 20:13:05 +02:00
|
|
|
const listenSocket = this.config.get('server.socket');
|
2021-08-03 09:12:58 +02:00
|
|
|
|
2021-08-09 20:13:05 +02:00
|
|
|
if (listenSocket) {
|
|
|
|
return this.server.listen(listenSocket, onListen);
|
2021-08-03 09:12:58 +02:00
|
|
|
}
|
2020-03-14 17:35:25 +01:00
|
|
|
|
2021-08-09 20:13:05 +02:00
|
|
|
const { host, port } = this.config.get('server');
|
|
|
|
return this.server.listen(port, host, onListen);
|
|
|
|
});
|
2016-07-26 11:57:50 +02:00
|
|
|
}
|
|
|
|
|
2020-03-12 16:05:39 +01:00
|
|
|
stopWithError(err, customMessage) {
|
2019-04-05 16:11:09 +02:00
|
|
|
this.log.debug(`⛔️ Server wasn't able to start properly.`);
|
2020-03-12 16:05:39 +01:00
|
|
|
if (customMessage) {
|
|
|
|
this.log.error(customMessage);
|
|
|
|
}
|
2021-06-17 16:17:15 +02:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
this.log.error(err);
|
|
|
|
return this.stop();
|
|
|
|
}
|
|
|
|
|
2019-12-28 17:09:00 +01:00
|
|
|
stop(exitCode = 1) {
|
2021-08-05 11:32:56 +02:00
|
|
|
this.server.destroy();
|
2017-09-04 15:38:29 +02:00
|
|
|
|
2021-07-08 11:20:13 +02:00
|
|
|
if (this.config.get('autoReload')) {
|
2017-10-02 14:17:44 +02:00
|
|
|
process.send('stop');
|
|
|
|
}
|
2017-09-04 15:38:29 +02:00
|
|
|
|
2021-03-29 12:33:08 +02:00
|
|
|
// Kill process
|
2019-12-28 17:09:00 +01:00
|
|
|
process.exit(exitCode);
|
2016-07-26 11:57:50 +02:00
|
|
|
}
|
|
|
|
|
2021-08-03 09:12:58 +02:00
|
|
|
loadAdmin() {
|
|
|
|
this.admin = require('@strapi/admin/strapi-server');
|
|
|
|
|
|
|
|
// TODO: rename into just admin and ./config/admin.js
|
|
|
|
const userAdminConfig = strapi.config.get('server.admin');
|
|
|
|
this.config.set('server.admin', _.merge(this.admin.config, userAdminConfig));
|
|
|
|
}
|
|
|
|
|
2017-07-24 19:58:03 +02:00
|
|
|
async load() {
|
2017-10-02 14:17:44 +02:00
|
|
|
this.app.use(async (ctx, next) => {
|
2020-10-08 00:33:32 -07:00
|
|
|
if (ctx.request.url === '/_health' && ['HEAD', 'GET'].includes(ctx.request.method)) {
|
2018-03-14 13:18:05 +01:00
|
|
|
ctx.set('strapi', 'You are so French!');
|
2017-10-02 14:17:44 +02:00
|
|
|
ctx.status = 204;
|
2017-09-06 11:06:18 +02:00
|
|
|
} else {
|
|
|
|
await next();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-08-06 18:09:49 +02:00
|
|
|
const plugins = await loadPlugins(this);
|
|
|
|
|
|
|
|
for (const pluginName in plugins) {
|
|
|
|
const plugin = plugins[pluginName];
|
|
|
|
this.container.get('modules').add(`plugin::${pluginName}`, plugin);
|
|
|
|
}
|
|
|
|
|
2021-08-05 13:59:40 +02:00
|
|
|
// await this.container.load();
|
2021-05-31 18:28:42 +02:00
|
|
|
|
2021-08-05 13:59:40 +02:00
|
|
|
// this.plugins = this.container.plugins.getAll();
|
2019-05-02 17:51:58 +02:00
|
|
|
|
2021-07-29 16:39:26 +02:00
|
|
|
const modules = await loadModules(this);
|
|
|
|
|
2021-08-03 09:12:58 +02:00
|
|
|
this.loadAdmin();
|
2021-08-03 08:33:47 +02:00
|
|
|
|
2021-07-08 11:20:13 +02:00
|
|
|
this.api = modules.api;
|
|
|
|
this.components = modules.components;
|
|
|
|
|
|
|
|
this.middleware = modules.middlewares;
|
|
|
|
this.hook = modules.hook;
|
|
|
|
|
|
|
|
await bootstrap(this);
|
2019-05-02 17:51:58 +02:00
|
|
|
|
2020-01-10 12:42:57 +01:00
|
|
|
// init webhook runner
|
|
|
|
this.webhookRunner = createWebhookRunner({
|
|
|
|
eventHub: this.eventHub,
|
|
|
|
logger: this.log,
|
2020-04-03 22:31:20 +02:00
|
|
|
configuration: this.config.get('server.webhooks', {}),
|
2020-01-10 12:42:57 +01:00
|
|
|
});
|
|
|
|
|
2021-02-16 12:23:51 +01:00
|
|
|
await this.runLifecyclesFunctions(LIFECYCLES.REGISTER);
|
2021-07-19 16:47:24 +02:00
|
|
|
|
2021-06-17 16:17:15 +02:00
|
|
|
const contentTypes = [
|
2021-05-17 16:34:19 +02:00
|
|
|
coreStoreModel,
|
|
|
|
webhookModel,
|
2021-07-19 16:47:24 +02:00
|
|
|
...Object.values(strapi.contentTypes),
|
2021-05-17 16:34:19 +02:00
|
|
|
...Object.values(strapi.components),
|
|
|
|
];
|
|
|
|
|
2021-06-28 12:34:29 +02:00
|
|
|
this.db = await Database.init({
|
2021-05-17 16:34:19 +02:00
|
|
|
...this.config.get('database'),
|
2021-06-17 16:17:15 +02:00
|
|
|
models: Database.transformContentTypes(contentTypes),
|
2021-05-17 16:34:19 +02:00
|
|
|
});
|
2021-02-12 12:52:29 +01:00
|
|
|
|
2021-07-05 18:35:16 +02:00
|
|
|
await this.db.schema.sync();
|
2019-09-20 12:44:24 +02:00
|
|
|
|
2021-07-08 11:20:13 +02:00
|
|
|
this.store = createCoreStore({
|
|
|
|
environment: this.config.environment,
|
|
|
|
db: this.db,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.webhookStore = createWebhookStore({ db: this.db });
|
2019-12-17 11:24:14 +01:00
|
|
|
|
2021-07-08 11:20:13 +02:00
|
|
|
await this.startWebhooks();
|
2019-12-17 20:59:57 +01:00
|
|
|
|
2020-09-22 12:31:26 +02:00
|
|
|
this.entityValidator = entityValidator;
|
2020-02-17 11:31:34 +01:00
|
|
|
|
2020-01-08 11:12:41 +01:00
|
|
|
this.entityService = createEntityService({
|
2021-07-19 19:36:40 +02:00
|
|
|
strapi: this,
|
2020-01-08 11:12:41 +01:00
|
|
|
db: this.db,
|
|
|
|
eventHub: this.eventHub,
|
2020-02-17 11:31:34 +01:00
|
|
|
entityValidator: this.entityValidator,
|
2020-01-08 11:12:41 +01:00
|
|
|
});
|
|
|
|
|
2020-03-27 15:30:03 +01:00
|
|
|
this.telemetry = createTelemetry(this);
|
2020-03-27 10:30:43 +01:00
|
|
|
|
2021-08-09 17:33:02 +02:00
|
|
|
// Initialize middlewares.
|
2021-07-08 11:20:13 +02:00
|
|
|
await initializeMiddlewares.call(this);
|
2020-05-05 14:21:23 +02:00
|
|
|
|
2021-02-16 12:23:51 +01:00
|
|
|
await this.runLifecyclesFunctions(LIFECYCLES.BOOTSTRAP);
|
2021-07-08 11:20:13 +02:00
|
|
|
|
2020-05-12 12:47:23 +02:00
|
|
|
this.isLoaded = true;
|
2020-05-07 18:49:44 +02:00
|
|
|
return this;
|
2016-07-26 11:57:50 +02:00
|
|
|
}
|
|
|
|
|
2021-07-08 11:20:13 +02:00
|
|
|
async startWebhooks() {
|
|
|
|
const webhooks = await this.webhookStore.findWebhooks();
|
|
|
|
webhooks.forEach(webhook => this.webhookRunner.add(webhook));
|
|
|
|
}
|
2019-12-17 20:59:57 +01:00
|
|
|
|
2017-08-02 11:25:18 +02:00
|
|
|
reload() {
|
2018-03-28 20:13:09 +02:00
|
|
|
const state = {
|
2019-04-09 12:09:03 +02:00
|
|
|
shouldReload: 0,
|
2018-03-28 20:13:09 +02:00
|
|
|
};
|
|
|
|
|
2019-04-09 12:09:03 +02:00
|
|
|
const reload = function() {
|
2018-08-31 13:47:10 +02:00
|
|
|
if (state.shouldReload > 0) {
|
2018-07-15 15:51:30 +02:00
|
|
|
// Reset the reloading state
|
2018-08-31 13:47:10 +02:00
|
|
|
state.shouldReload -= 1;
|
2018-07-15 15:51:30 +02:00
|
|
|
reload.isReloading = false;
|
2018-03-28 20:13:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-13 15:35:19 +02:00
|
|
|
if (this.config.get('autoReload')) {
|
2021-08-04 20:13:35 +02:00
|
|
|
this.server.destroy();
|
2018-01-04 16:03:34 +01:00
|
|
|
process.send('reload');
|
|
|
|
}
|
2017-08-02 11:25:18 +02:00
|
|
|
};
|
|
|
|
|
2018-03-28 20:13:09 +02:00
|
|
|
Object.defineProperty(reload, 'isWatching', {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
2018-05-18 14:22:24 +02:00
|
|
|
set: value => {
|
2018-03-28 20:13:09 +02:00
|
|
|
// Special state when the reloader is disabled temporarly (see GraphQL plugin example).
|
2018-08-31 13:47:10 +02:00
|
|
|
if (state.isWatching === false && value === true) {
|
|
|
|
state.shouldReload += 1;
|
|
|
|
}
|
2018-03-28 20:13:09 +02:00
|
|
|
state.isWatching = value;
|
2018-05-02 22:16:13 +02:00
|
|
|
},
|
|
|
|
get: () => {
|
|
|
|
return state.isWatching;
|
2018-05-18 14:22:24 +02:00
|
|
|
},
|
2018-03-28 20:13:09 +02:00
|
|
|
});
|
|
|
|
|
2017-08-02 11:25:18 +02:00
|
|
|
reload.isReloading = false;
|
|
|
|
reload.isWatching = true;
|
|
|
|
|
|
|
|
return reload;
|
2016-07-26 11:57:50 +02:00
|
|
|
}
|
|
|
|
|
2021-06-08 10:39:45 +02:00
|
|
|
async runBootstraps() {
|
|
|
|
for (const plugin of this.plugin.getAll()) {
|
|
|
|
await plugin.bootstrap(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async runRegisters() {
|
|
|
|
for (const plugin of this.plugin.getAll()) {
|
|
|
|
await plugin.register(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-16 12:23:51 +01:00
|
|
|
async runLifecyclesFunctions(lifecycleName) {
|
|
|
|
const execLifecycle = async fn => {
|
|
|
|
if (!fn) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-12 15:35:40 +02:00
|
|
|
|
2020-07-01 19:11:04 +02:00
|
|
|
return fn();
|
2020-02-26 18:34:45 +01:00
|
|
|
};
|
2019-08-12 15:35:40 +02:00
|
|
|
|
2021-02-16 12:23:51 +01:00
|
|
|
const configPath = `functions.${lifecycleName}`;
|
2021-02-15 11:38:50 +01:00
|
|
|
|
2021-02-16 12:23:51 +01:00
|
|
|
// plugins
|
2021-08-06 18:09:49 +02:00
|
|
|
if (lifecycleName === LIFECYCLES.BOOTSTRAP) {
|
|
|
|
await this.container.get('modules').bootstrap();
|
|
|
|
} else if (lifecycleName === LIFECYCLES.REGISTER) {
|
|
|
|
await this.container.get('modules').register();
|
|
|
|
}
|
2019-04-05 16:11:09 +02:00
|
|
|
|
2021-02-16 12:23:51 +01:00
|
|
|
// user
|
2021-07-08 11:20:13 +02:00
|
|
|
await execLifecycle(this.config.get(configPath));
|
2020-06-08 15:13:26 +02:00
|
|
|
|
2021-02-16 12:23:51 +01:00
|
|
|
// admin
|
2021-02-15 11:38:50 +01:00
|
|
|
const adminFunc = _.get(this.admin.config, configPath);
|
2021-02-16 12:23:51 +01:00
|
|
|
return execLifecycle(adminFunc).catch(err => {
|
|
|
|
strapi.log.error(`${lifecycleName} function in admin failed`);
|
2021-06-17 19:51:35 +02:00
|
|
|
console.error(err);
|
2020-11-27 15:58:50 +01:00
|
|
|
strapi.stop();
|
2020-06-08 15:13:26 +02:00
|
|
|
});
|
2016-07-26 11:57:50 +02:00
|
|
|
}
|
|
|
|
|
2021-06-28 22:37:19 +02:00
|
|
|
getModel(uid) {
|
2021-07-01 13:52:01 +02:00
|
|
|
return this.contentTypes[uid] || this.components[uid];
|
2019-07-22 12:15:54 +02:00
|
|
|
}
|
|
|
|
|
2019-05-16 21:37:45 +02:00
|
|
|
/**
|
|
|
|
* Binds queries with a specific model
|
2021-06-30 20:00:03 +02:00
|
|
|
* @param {string} uid
|
|
|
|
* @returns {}
|
2019-05-16 21:37:45 +02:00
|
|
|
*/
|
2021-06-30 20:00:03 +02:00
|
|
|
query(uid) {
|
|
|
|
return this.db.query(uid);
|
2017-08-29 19:34:34 +02:00
|
|
|
}
|
2016-07-26 11:57:50 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 09:32:16 +02:00
|
|
|
module.exports = options => {
|
2021-07-20 12:12:30 +02:00
|
|
|
const strapi = new Strapi(options);
|
2019-04-11 09:32:16 +02:00
|
|
|
global.strapi = strapi;
|
|
|
|
return strapi;
|
|
|
|
};
|
2021-06-30 20:00:03 +02:00
|
|
|
|
|
|
|
module.exports.Strapi = Strapi;
|