groundwork for pubsub
This commit is contained in:
parent
cacee947bf
commit
0ea48245cf
|
@ -43,9 +43,7 @@ exports.save = async function(ctx) {
|
||||||
record.type = "record"
|
record.type = "record"
|
||||||
const response = await db.post(record)
|
const response = await db.post(record)
|
||||||
record._rev = response.rev
|
record._rev = response.rev
|
||||||
// await ctx.publish(events.recordApi.save.onRecordCreated, {
|
ctx.eventPublisher.emit("RECORD_CREATED", record)
|
||||||
// record: record,
|
|
||||||
// })
|
|
||||||
|
|
||||||
ctx.body = record
|
ctx.body = record
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
|
|
|
@ -4,6 +4,7 @@ const logger = require("koa-pino-logger")
|
||||||
const http = require("http")
|
const http = require("http")
|
||||||
const api = require("./api")
|
const api = require("./api")
|
||||||
const env = require("./environment")
|
const env = require("./environment")
|
||||||
|
const eventPublisher = require("./events");
|
||||||
|
|
||||||
const app = new Koa()
|
const app = new Koa()
|
||||||
|
|
||||||
|
@ -19,6 +20,8 @@ app.use(
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
app.context.publisher = eventPublisher;
|
||||||
|
|
||||||
// api routes
|
// api routes
|
||||||
app.use(api.routes())
|
app.use(api.routes())
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
const EventEmitter = require("events").EventEmitter;
|
||||||
|
|
||||||
|
module.exports = new EventEmitter();
|
Loading…
Reference in New Issue