Skip to content

Instantly share code, notes, and snippets.

@xiaoDC
Forked from bkonkle/Router.re
Created March 26, 2018 09:29
Show Gist options
  • Save xiaoDC/4d9849935f1dd0bc0c2da8a6b3412505 to your computer and use it in GitHub Desktop.
Save xiaoDC/4d9849935f1dd0bc0c2da8a6b3412505 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