Small micro-channel routing reform program

A user can only create 50 cloud function in a cloud environment, we can create multiple routing function in a cloud, which can reduce the number of cloud function.

Raja on small micro-channel pull-down refresh program contained articles to achieve a single song by calling cloud function, now to be rehabilitated by routing tcb-router

Right cloud music function, click open terminal
Here Insert Picture Description
enter the following command to install tcb-router

npm install --save tcb-router


js cloud music file function modified as follows:

// 云函数入口文件
const cloud = require('wx-server-sdk')
const TcbRouter = require('tcb-router')
const rp = require('request-promise')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
  const app = new TcbRouter({
    event
  })
  app.router('playlist', async (ctx, next) => {
    ctx.body = await cloud.database().collection('playlist')
      .skip(event.start)
      .limit(event.count)
      .orderBy('createTime', 'desc')
      .get()
      .then((res) => {
        return res
      })
  })
  return app.serve()
  // const playlist = await cloud.database().collection('playlist')
  //   .skip(event.start)
  //   .limit(event.count)
  //   .orderBy('createTime', 'desc')
  //   .get()
  //   .then((res) => {
  //     console.log(res)
  //     return res
  //   })
  // return playlist
}

We can also create a list of songs musiclist routing, routing lyric lyrics, songs address musicUrl routing in the cloud music function, so that multiple similar functions into a cloud to function, distinguished by routing, reducing the creation of cloud function.

Upload cloud function

Add the following code to the red box in the demo.js.
Here Insert Picture Description

Published 446 original articles · won praise 67 · views 240 000 +

Guess you like

Origin blog.csdn.net/hongxue8888/article/details/104610559