groundwork for pubsub

This commit is contained in:
Martin McKeaveney 2020-05-24 22:54:08 +01:00
parent cacee947bf
commit 0ea48245cf
3 changed files with 7 additions and 3 deletions

View File

@ -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

View File

@ -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())

View File

@ -0,0 +1,3 @@
const EventEmitter = require("events").EventEmitter;
module.exports = new EventEmitter();