1.0.39 • Published 1 month ago

gg-unicloud-router v1.0.39

Weekly downloads
-
License
-
Repository
-
Last release
1 month ago
unicloud云开发路由库
> A.路由鉴权
> B.前置中间件 后置中间件
> C.自定义响应体
const { createRouter } = require("gg-unicloud-router");
// const {createRouter} = require('../index');
const path = require("path");
const router = createRouter({
  root: path.resolve(__dirname, "./routers"),
  permissions: {
    //**代表模糊匹配多级目录 *代表模糊匹配当前目录
    "test/test": "auth && auth.uid",
    "test/test/**": true,
    "*": (action, event, context, auth) => {
      return false;
    },
  },
  response: (action, data, error) => {
    if (error) {
      return {
        code: error.code || 500,
        message: error.message || "服务器内部错误",
      };
    }
    if (action.indexOf("wechat") > -1) {
      return data;
    }
    return {
      code: 200,
      message: "操作成功",
      result: data,
    };
  },
  timers: [
    {
      name: "test/test",
      desc: "name指定子路由名称,desc表示子路由定时器触发的概率100为100%",
      weight: 0,
      config: "33 33 * * * * *",
    },
  ],
  before: [
    function (action, event, context, next) {
      console.log("前置中间件");
      next();
    },
  ],
  after: [
    function (action, event, context, data, next) {
      console.log("后置中间件");
      next(data);
    },
  ],
});

setTimeout(async () => {
  //模拟http
  // console.log(await router.serve({
  //     httpMethod:"POST",
  //     queryStringParameters:{
  //         "$action":"test/test2",
  //     },
  // },{SOURCE:'http'}))

  //模拟unicloud客户端
  // console.log(await router.serve({
  //         "$action":"test/test",

  //         // "timingTriggerConfig": "cron:33 33 * * * *",
  //         // "timestamp": 1654749213106
  //     },{}))

  //模拟定时器
  // console.log(await router.serve({
  //         "timingTriggerConfig": "cron:33 33 * * * *",
  //         "timestamp": 1654749213106
  //     },{}))

  //子路由调用子路由
  context.callFunction({
    name: "xxx/xxx",
    data: {},
  });
});
1.0.37

1 month ago

1.0.39

1 month ago

1.0.38

1 month ago

1.0.36

1 month ago

1.0.26

1 month ago

1.0.25

1 month ago

1.0.29

1 month ago

1.0.28

1 month ago

1.0.27

1 month ago

1.0.33

1 month ago

1.0.31

1 month ago

1.0.30

1 month ago

1.0.34

1 month ago

1.0.19

2 months ago

1.0.18

2 months ago

1.0.17

2 months ago

1.0.16

2 months ago

1.0.9

2 months ago

1.0.8

2 months ago

1.0.22

2 months ago

1.0.21

2 months ago

1.0.20

2 months ago

1.0.24

2 months ago

1.0.11

2 months ago

1.0.10

2 months ago

1.0.15

2 months ago

1.0.14

2 months ago

1.0.13

2 months ago

1.0.12

2 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.3

11 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.3.11

1 year ago

0.0.15

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.2.9

1 year ago

0.1.9

1 year ago

0.0.5

1 year ago

0.1.6

1 year ago

0.0.7

1 year ago

0.1.5

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago