-
-
Save xiaoDC/4d9849935f1dd0bc0c2da8a6b3412505 to your computer and use it in GitHub Desktop.
Reason with Koa Router
This file contains 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
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