npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tcb-server-sdk

v1.1.3

Published

云开发云函数轻量级类路由库,主要用于优化服务端函数处理逻辑

Downloads

16

Readme

tcb-server-sdk

云开发云函数轻量级类路由库,主要用于优化服务端函数处理逻辑

说明:
  • 被路由的处理类要求继承RouteBase
  • 云函数入口使用RouteHolder初始化路由对象,允许指定固定前缀
  • RouteBase会自动使用wx-server-sdk初始化云环境
其中:
  • RouteBase还会初始化一些云函数所需的操作对象

示例

云函数端

目录结构
\--- functions
	 +--- routeTest
	 	  +---- service
		  |		+---- user
		  |			  \---- Name.js
		  |		\---- Test.js
		  \---- index.js
		  \---- package.json
		  \---- package-lock.json
入口文件
const route = require("./tcb-server-sdk");

// 云函数入口函数
exports.main = async (event, context) => {

    console.log("入参:", event);
    //根据目录结构可以指定固定前缀为service
    //小程序端就可以使用user/Name/get访问到Name处理类里的get方法
    //如果不指定固定前缀,则需要使用service/user/Name/get才能访问到Name处理类里的get方法
    return await new route.RouteHolder("service").process(event);
};
请求处理类 Name.js
const route = require("./tcb-server-sdk");

class Name extends route.RouteBase {
    async index(params) {
    	console.log("这个是index方法:", params);
        return {};
    }
    
    async get(params) {
        console.log("接口请求参数:", params);
        //这里的this.wxContext来自RouteBase
        return {"idol": "kobe", "wxContext": this.wxContext};
    }
}

module.exports = Name;
小程序端
//执行云函数
wx.cloud.callFunction({
    // 云函数名称
    name: "routeTest",
    // 传给云函数的参数
    data: {
        env: "test",// 环境可以不填,不填就使用当前环境  
        uri: "user/Name/get",//请求URI,云函数端的RouteHolder会找到对应的处理类并调用指定方法。这里会调用Name类的get方法
        //uri: "user/Name",//这种方式会默认调用Name类的index方法
        params: {"source":"1"}
    }
}).then(res => {

}).catch(res => {

}).then(res => {

});

开源链接:

https://github.com/showms/tcb-server-sdk.git