云函数路由

发布于 7 年前作者 chaoyuan804 次浏览最后编辑 7 年前来自 ask

npm  tcb-router到云开发本地目录后,怎么将这个同步到云端???

跪求…或,云函数怎么写路由????

1 回复
fanghan
fanghan1 楼5 年前

// 云函数入口文件  

const cloud = require(‘wx-server-sdk’);

const TcbRouter = require(‘tcb-router’);

cloud.init()

const db = cloud.database();

const _ = db.command;

// 云函数入口函数

exports.main = async (event, context) => {

const app = new TcbRouter({ event });

/**

 * 登录

 */

app.router(‘login’, async (ctx, next) => {

await next();

}, async (ctx, next) => {

await next();

}, async (ctx) => {

const login = require(‘login/index.js’);

ctx.body = login.mian(event, context, db, _);

});

return app.serve();

}

安装相关依赖右键上传上去即可