Created
October 10, 2022 20:25
-
-
Save trezy/24328d29fdb064c9a0b91b8133be95a0 to your computer and use it in GitHub Desktop.
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
import { EventSubMiddleware } from '@twurple/eventsub' | |
import Koa from 'koa' | |
import KoaRouter from 'koa-router' | |
const app = new Koa | |
const router = new KoaRouter | |
const middleware = new EventSubMiddleware('...') | |
const middlewareHandlerWrapper = method => (path, handler) => { | |
router[method](path, (context, next) => { | |
context.req.params = context.params | |
return handler(context.req, context.res, next) | |
}) | |
} | |
middleware.apply({ | |
get: middlewareHandlerWrapper('get'), | |
post: middlewareHandlerWrapper('post'), | |
}) | |
app.use(router.routes()) | |
app.use(router.allowedMethods()) | |
app.listen(process.env.PORT ?? 3000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment