JSPM

  • Created
  • Published
  • 0
  • Score
    100M100P100Q74418F
  • License MIT

koa.js bindings for rescript.

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@futurert/rescript-koa) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Rescript-Koa

    NPM npm

    example

    install

    npm install @futurert/rescript-koa --save-dev

    bsconfig

    You should add "@futurert/rescript-koa" in bs-dependencies, just like this:

    {
      "name": "rescript-project-template",
      "version": "0.0.1",
      "sources": {
        "dir" : "src",
        "subdirs" : true
      },
      "package-specs": {
        "module": "commonjs",
        "in-source": true
      },
      "bs-dependencies": [
        "@futurert/rescript-koa",
      ],
      "warnings": {
        "error" : "+101"
      }
    }

    Get First Koa App

    Koa is great for its middleware design, we just can use sync function as app->use() function params, just like here:

    open KoaJs.Koa
    // init koa app
    let app = koa(koaOptions())
    
    // Just for instance.
    // app.env = "development"
    
    // you can use middleware like this
    app->App.use(async (context, next) => {
      Js.log("1")
      context.body = "hello"
      await next();
      Js.log("2")
    })
    
    app->App.use(async (_, next) => {
      Js.log("3")
      await next()
      Js.log("4")
    })
    
    app->App.env("哈哈哈")
    
    app->App.listen(~port = 3000, ~host= "127.0.0.1", ~callback= _ => Js.log("哈哈哈"))
    // Js.log(app->App.env) 
    
    // app.listen()
    app->App.on("error", (err, ctx) => Js.log(err))

    There is a full example to help you start, Let's try it!