0.0.21 • Published 3 years ago

@medomino-170/koa-server v0.0.21

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

快速生成 nodejs(koa) 后端服务

示例

import { createServer, API, RouteItem } from "../src";

interface ExtensKey {
  body: {
    __token: {
      user: string;
    };
  };
  headers: {
    token: string;
  };
  extend: {
    compress: boolean;
  };
}

type Base = API<ExtensKey>;
type WrapRoute<T extends Record<string, any> = {}> = RouteItem<ExtensKey, T>;

const get: WrapRoute<{ lql: string }> = {
  method: "get",
  async callback({ body: { __token, lql }, ctx }) {
    console.log(__token, lql, ctx.query, ctx.search, ctx.request.body);
    return 123;
  },
};

const api: Base["api"] = {
  "/api": {
    "/v/": get,
  },
};

const intercept: Base["intercept"] = {
  "/api/(.*)": async (_ctx, next) => {
    await next();
  },
};

createServer({
  base: {
    port: 8000,
  },
  api: {
    api,
    intercept,
  },
});
0.0.21

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.16

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.5

3 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago