kisa
TypeScript icon, indicating that this package has built-in type declarations

0.5.2 • Public • Published

kisa

A web framework based on koa and openapi.

Usage

import useKisa, { Koa, Router, RoutesError } from "kisa";
import * as Api from "./apiType"; // generated with kisa-typegen

const app = new Koa();
app.use(bodyParser());
const router = new Router();
const { mountKisa } = useKisa<
  State,
  Api.Handlers<State>,
  Api.Middlewares<State>,
  Api.SecurityHandlers<State>
>({
  operations: Api.OPERATIONS,
  middlewares: {
    ratelimit: async (ctx, next) => {
      await next();
    },
  },
  securityHandlers: {
    jwt: () => {
      return async (ctx, next) => {
        if (ctx.headers["authorization"]) {
          ctx.state.auth = {
            user: ctx.headers["authorization"].slice("Bearer ".length),
          };
        }
        await next();
      };
    },
  },
  errorHandlers: {
    routes: (error) => {
      return;
    },
    validate: (errors) => {
      return;
    },
  },
});

kisa.handlers.login = async (ctx) => {};

mountKisa(router);
app.use(router.routes());
app.listen(3000);

Readme

Keywords

Package Sidebar

Install

npm i kisa

Weekly Downloads

5

Version

0.5.2

License

MIT

Unpacked Size

10.9 kB

Total Files

4

Last publish

Collaborators

  • sigoden