Skip to content

Instantly share code, notes, and snippets.

@bkonkle
Created November 10, 2017 15:23
Show Gist options
  • Save bkonkle/ec15aa81e99cc0827daf6c170124429e to your computer and use it in GitHub Desktop.
Save bkonkle/ec15aa81e99cc0827daf6c170124429e to your computer and use it in GitHub Desktop.
Reason with Koa Router
type koaRouter;
[@bs.module] external koaRouter : koaRouter = "koa-router";
[@bs.new] external newRouter : unit => koaRouter = "KoaRouter";
[@bs.send] external get : (koaRouter, string, 'a => Js.Promise.t(unit)) => unit = "";
[@bs.send] external post : (koaRouter, string, 'a => Js.Promise.t(unit)) => unit = "";
[@bs.send] external routes : koaRouter => 'a = "";
[@bs.send] external allowedMethods : koaRouter => 'a = "";
let init = (dataProvider) => {
koaRouter |> ignore; /* TODO: This is a workaround to get bs to import koa-router */
let router = newRouter();
let room = RoomHandler.init(dataProvider);
get(
router,
"/",
(ctx) => {
ctx##body#="ok";
Js.Promise.resolve()
}
);
post(router, "/room/link", room.postLink);
router
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment