mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
Merge branch 'features/webhooks' into front/webhooks-editview
This commit is contained in:
commit
58c15f9469
@ -152,7 +152,7 @@ To do so, you will have to request the `/articles` route in **POST**.
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
const {data} = await axios
|
const {data} = await axios
|
||||||
.get('http://localhost:1337/articles', {
|
.post('http://localhost:1337/articles', {
|
||||||
data: {
|
data: {
|
||||||
title: 'my article'
|
title: 'my article'
|
||||||
content: 'my super article content'
|
content: 'my super article content'
|
||||||
|
@ -128,7 +128,7 @@ module.exports = {
|
|||||||
await actions.delete(file);
|
await actions.delete(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
const media = strapi.query('file', 'upload').findOne({
|
const media = await strapi.query('file', 'upload').findOne({
|
||||||
id: file.id,
|
id: file.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ const CONFIG_PATHS = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class Strapi extends EventEmitter {
|
class Strapi extends EventEmitter {
|
||||||
constructor(opts) {
|
constructor(opts = {}) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.setMaxListeners(100);
|
this.setMaxListeners(100);
|
||||||
@ -86,24 +86,19 @@ class Strapi extends EventEmitter {
|
|||||||
this.dir = opts.dir || process.cwd();
|
this.dir = opts.dir || process.cwd();
|
||||||
this.admin = {};
|
this.admin = {};
|
||||||
this.plugins = {};
|
this.plugins = {};
|
||||||
this.config = {};
|
this.config = this.initConfig(opts);
|
||||||
|
|
||||||
// internal services.
|
// internal services.
|
||||||
this.fs = createStrapiFs(this);
|
this.fs = createStrapiFs(this);
|
||||||
this.eventHub = createEventHub();
|
this.eventHub = createEventHub();
|
||||||
this.webhookRunner = createWebhookRunner({
|
|
||||||
eventHub: this.eventHub,
|
|
||||||
logger: this.log,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.initConfig(opts);
|
|
||||||
this.requireProjectBootstrap();
|
this.requireProjectBootstrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
initConfig({ autoReload = false, serveAdminPanel = true } = {}) {
|
initConfig({ autoReload = false, serveAdminPanel = true } = {}) {
|
||||||
const pkgJSON = require(path.resolve(this.dir, 'package.json'));
|
const pkgJSON = require(path.resolve(this.dir, 'package.json'));
|
||||||
|
|
||||||
this.config = {
|
const config = {
|
||||||
serveAdminPanel,
|
serveAdminPanel,
|
||||||
launchedAt: Date.now(),
|
launchedAt: Date.now(),
|
||||||
appPath: this.dir,
|
appPath: this.dir,
|
||||||
@ -123,6 +118,26 @@ class Strapi extends EventEmitter {
|
|||||||
installedMiddlewares: getPrefixedDeps('strapi-middleware', pkgJSON),
|
installedMiddlewares: getPrefixedDeps('strapi-middleware', pkgJSON),
|
||||||
installedHooks: getPrefixedDeps('strapi-hook', pkgJSON),
|
installedHooks: getPrefixedDeps('strapi-hook', pkgJSON),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Object.defineProperty(config, 'get', {
|
||||||
|
value(path, defaultValue = null) {
|
||||||
|
return _.get(config, path, defaultValue);
|
||||||
|
},
|
||||||
|
enumerable: false,
|
||||||
|
configurable: false,
|
||||||
|
writable: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(config, 'set', {
|
||||||
|
value(path, value) {
|
||||||
|
return _.set(config, path, value);
|
||||||
|
},
|
||||||
|
enumerable: false,
|
||||||
|
configurable: false,
|
||||||
|
writable: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
requireProjectBootstrap() {
|
requireProjectBootstrap() {
|
||||||
@ -368,6 +383,13 @@ class Strapi extends EventEmitter {
|
|||||||
// Usage.
|
// Usage.
|
||||||
await utils.usage(this.config);
|
await utils.usage(this.config);
|
||||||
|
|
||||||
|
// init webhook runner
|
||||||
|
this.webhookRunner = createWebhookRunner({
|
||||||
|
eventHub: this.eventHub,
|
||||||
|
logger: this.log,
|
||||||
|
configuration: this.config.get('currentEnvironment.server.webhooks', {}),
|
||||||
|
});
|
||||||
|
|
||||||
// Init core store
|
// Init core store
|
||||||
this.models['core_store'] = coreStoreModel;
|
this.models['core_store'] = coreStoreModel;
|
||||||
this.models['strapi_webhooks'] = webhookModel;
|
this.models['strapi_webhooks'] = webhookModel;
|
||||||
|
@ -4,19 +4,32 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const debug = require('debug')('strapi');
|
const debug = require('debug')('strapi');
|
||||||
|
const _ = require('lodash');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
const WorkerQueue = require('./worker-queue');
|
const WorkerQueue = require('./worker-queue');
|
||||||
|
|
||||||
|
const defaultConfiguration = {
|
||||||
|
defaultHeaders: {},
|
||||||
|
};
|
||||||
|
|
||||||
class WebhookRunner {
|
class WebhookRunner {
|
||||||
constructor({ eventHub, logger, queue }) {
|
constructor({ eventHub, logger, configuration = {} }) {
|
||||||
debug('Initialized webhook runer');
|
debug('Initialized webhook runer');
|
||||||
this.eventHub = eventHub;
|
this.eventHub = eventHub;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.webhooksMap = new Map();
|
this.webhooksMap = new Map();
|
||||||
this.listeners = new Map();
|
this.listeners = new Map();
|
||||||
|
|
||||||
this.queue = queue || new WorkerQueue({ logger, concurency: 5 });
|
if (typeof configuration !== 'object') {
|
||||||
|
throw new Error(
|
||||||
|
'Invalid configuration provided to the webhookRunner.\nCheck your server.json -> webhooks configuration'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.config = _.merge(defaultConfiguration, configuration);
|
||||||
|
|
||||||
|
this.queue = new WorkerQueue({ logger, concurency: 5 });
|
||||||
this.queue.subscribe(this.executeListener.bind(this));
|
this.queue.subscribe(this.executeListener.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,6 +85,7 @@ class WebhookRunner {
|
|||||||
...info,
|
...info,
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
|
...this.config.defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
'X-Strapi-Event': event,
|
'X-Strapi-Event': event,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
24
scripts/publish.sh
Executable file
24
scripts/publish.sh
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
# Force start from root folder
|
||||||
|
cd "$(dirname "$0")/.."
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
version=""
|
||||||
|
|
||||||
|
echo "Please enter the version you want to publish"
|
||||||
|
read version
|
||||||
|
|
||||||
|
# publish packages
|
||||||
|
./node_modules/.bin/lerna publish --no-push --dist-tag beta --exact "$version"
|
||||||
|
|
||||||
|
# push master branch
|
||||||
|
git push origin master
|
||||||
|
|
||||||
|
# push tag
|
||||||
|
git push origin v"$version"
|
||||||
|
|
||||||
|
# set latest dist-tag on npm
|
||||||
|
lerna exec --stream --no-bail --no-private -- npm dist-tag add '${LERNA_PACKAGE_NAME}'@"$version" latest
|
||||||
|
|
||||||
|
# run changelog cli
|
||||||
|
npx @sclt/program-changelog
|
Loading…
x
Reference in New Issue
Block a user