
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
@mpneon/cloud
Advanced tools
微信小程序云函数框架
新建一个云函数 neon
,安装 @mpneon/cloud
作为它的依赖。
使用 app.route()
方法创建路由。
// 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);
在小程序端调用时,调用云函数 neon
,并传入 $path
字段表示要访问的函数路由。
// app.js
wx.cloud.callFunction({
// 云函数名称
name: 'neon',
// 传给云函数的参数
data: {
$path: 'sum',
a: 1,
b: 2,
},
success: function(res) {
console.log(res.result) // 3
},
fail: console.error
})
你可以从 request.user
字段(异步)获取发起当前请求的用户。
// 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)
若要使用定时任务,须根据小程序文档设置一个每分钟执行的定时触发器。
// config.json
{
"triggers": [
{
"name": "neon.schedule",
"type": "timer",
"config": "0 * * * * * *"
}
]
}
然后使用 app.cron()
方法注册你的定时任务。
// task.js
module.exports = (request, { cloud, db, ...context }) => {
console.log('Taske invoked every other minute')
}
// index.js
const app = new (require('@mpneon/cloud').Application)();
app.route('sum', require('./sum'))
app.cron('*/2 * * * *', require('./task'))
exports.main = (event, context) => app.handle(event, context);
注意 app.cron()
方法只支持标准 Cron 表达式,即不支持秒和年。
MIT Licensed.
FAQs
The npm package @mpneon/cloud receives a total of 1 weekly downloads. As such, @mpneon/cloud popularity was classified as not popular.
We found that @mpneon/cloud demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.