Skip to content

Instantly share code, notes, and snippets.

@RickWong
Last active June 6, 2018 08:51
Show Gist options
  • Save RickWong/4a98563abb7f7d918477f3bcf809c154 to your computer and use it in GitHub Desktop.
Save RickWong/4a98563abb7f7d918477f3bcf809c154 to your computer and use it in GitHub Desktop.
Rikkert Framework
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");
});
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