Last active
June 6, 2018 08:51
-
-
Save RickWong/4a98563abb7f7d918477f3bcf809c154 to your computer and use it in GitHub Desktop.
Rikkert Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { listen, emit } = require("rikkert"); | |
const express = require('express'); | |
const app = express(); | |
const rikkertMiddleware = (req, res, next) => { | |
emit("http.request", { req, res }).then(next); | |
}; | |
app.use(rikkertMiddleware); | |
app.listen(3000); | |
listen("http.request", async ({ req, res }) => { | |
res.json("hello world"); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { EventEmitter2 } = require("eventemitter2"); | |
const emitter = new EventEmitter2({ wildcard: true }); | |
const listen = (name, listener) => emitter.on(name, listener); | |
const emit = async (name, payload = {}) => emitter.emitAsync(name, payload); | |
module.exports = { listen, emit }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment