Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mpneon/cloud

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mpneon/cloud

> 微信小程序云函数框架

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

@mpneon/cloud

微信小程序云函数框架

特性

  • 云函数路由(代码共享)

Usage

路由

// sum.js
module.exports = (request, { cloud, db, ...context }) => {
    const { a, b } = request.event

    return a + b
}
// index.js
const app = new (require('@mpneon/cloud').Application)();

app.route('sum', require('./sum'))

exports.main = (event, context) => app.handle(event, context);

获取当前请求用户 @since 1.1.0

// user.js
module.exports = async (request, { cloud, db, ...context }) => {

    const user = await request.user

    return user
}

默认情况下,会从云数据库的 users 集合中查询 _id 为当前 OPENID 的记录。如果你需要自定义解析当前用户的方法,使用 app.useUserResolver((openid, requestcontext) => Promise<any>)

// index.js

app.route('user', require('./user'))

app.useUserResolver((openid, { cloud, db, ...context }) => new Promise(resolve => {
  // 取 users 集合中 openid 字段为 OPENID 的记录
  db.collection("users")
    .where({
      openid
    })
    .get()
    .then(({ data: users}) => resolve(users[0] || null));
}))

exports.main = (event, context) => app.handle(event, context)

License

MIT Licensed.

FAQs

Package last updated on 23 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc