groundwork for pubsub
This commit is contained in:
parent
cacee947bf
commit
0ea48245cf
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
const EventEmitter = require("events").EventEmitter;
|
||||
|
||||
module.exports = new EventEmitter();
|
Loading…
Reference in New Issue