@wize/runtime-load-routes

Load API routes

Usage no npm install needed!

<script type="module">
  import wizeRuntimeLoadRoutes from 'https://cdn.skypack.dev/@wize/runtime-load-routes';
</script>

README

@wize/runtime-load-routes

Description

Registers routes for custom APIs defined in apis directory.

Usage

Installation

npm install --save @wize/runtime-load-routes

Initialize

import runtime from '@wize/runtime-load-routes';
.
.
.
/*
app: koa-app returned from 'const app = createServer({});'
directory: current directory containing all API folders
opts: JSON object; example: {isAPI: true}
events: JSON object containing pre and post events to be attached to each route; example: { pre: [setUserObjectInContext], post: []}
*/
runtime(app, directory, {
    isAPI: true
  }, events);

Sample API directory

project
└───api
│   └───audits
│       └───GET
│           │   index.js
│           │   config.json
│   │   index.js
└───sources
│   └───postgres
│       │   index.js
│   app.js
│   README.md

License

MIT License