diff --git a/packages/server/src/api/controllers/record.js b/packages/server/src/api/controllers/record.js index 2cd648b6c3..53261cb8ec 100644 --- a/packages/server/src/api/controllers/record.js +++ b/packages/server/src/api/controllers/record.js @@ -43,9 +43,7 @@ exports.save = async function(ctx) { record.type = "record" const response = await db.post(record) record._rev = response.rev - // await ctx.publish(events.recordApi.save.onRecordCreated, { - // record: record, - // }) + ctx.eventPublisher.emit("RECORD_CREATED", record) ctx.body = record ctx.status = 200 diff --git a/packages/server/src/app.js b/packages/server/src/app.js index bec5f8d16e..f947738567 100644 --- a/packages/server/src/app.js +++ b/packages/server/src/app.js @@ -4,6 +4,7 @@ const logger = require("koa-pino-logger") const http = require("http") const api = require("./api") const env = require("./environment") +const eventPublisher = require("./events"); const app = new Koa() @@ -19,6 +20,8 @@ app.use( }) ) +app.context.publisher = eventPublisher; + // api routes app.use(api.routes()) diff --git a/packages/server/src/events/index.js b/packages/server/src/events/index.js new file mode 100644 index 0000000000..14e4e052e1 --- /dev/null +++ b/packages/server/src/events/index.js @@ -0,0 +1,3 @@ +const EventEmitter = require("events").EventEmitter; + +module.exports = new EventEmitter(); \ No newline at end of file