Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'leanengine' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
it('response have captchaId and imageUrl', async () => {
const result = await AV.Cloud.run('getCaptchaImageStorage')
result.should.have.properties(['captchaId', 'imageUrl'])
captchaId = result.captchaId
await new AV.Query('Captcha').find().then( captchas => {
// 因为设置了 ACL,所以非特殊账号无法查询到 captcha 对象
captchas.length.should.equal(0)
})
})
})
'use strict';
var AV = require('leanengine');
AV.init({
appId: process.env.LEANCLOUD_APP_ID,
appKey: process.env.LEANCLOUD_APP_KEY,
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY
});
AV.Cloud.useMasterKey();
var app = require('./app');
// 端口一定要从环境变量 `LEANCLOUD_APP_PORT` 中获取。
// LeanEngine 运行时会分配端口并赋值到该变量。
var PORT = parseInt(process.env.LEANCLOUD_APP_PORT || process.env.PORT || 3000);
app.listen(PORT, function (err) {
console.log('Node app is running on port:', PORT);
// 注册全局未捕获异常处理器
process.on('uncaughtException', function(err) {
console.error("Caught exception:", err.stack);
});
process.on('unhandledRejection', function(reason, p) {
console.error("Unhandled Rejection at: Promise ", p, " reason: ", reason.stack);
console.log('cleanup-files');
return new AV.Query(AV.File).limit(999).destroyAll({ useMasterKey: true }).then(function() {
console.log('Files deleted');
}, function(error) {
console.error('cleanup files error: ' + error.message);
});
});
// handle uncaught exceptions so the application cannot crash
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
console.trace();
});
// leanengine health checker
app.use(AV.express());
// start the server
var PORT = process.env.LEANCLOUD_APP_PORT || process.env.PORT || 8080;
app.listen(PORT, function () {
console.log('Listening at http://localhost:' + PORT);
});
'use strict';
var AV = require('leanengine');
AV.init({
appId: process.env.LEANCLOUD_APP_ID,
appKey: process.env.LEANCLOUD_APP_KEY,
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY
});
// 如果不希望使用 masterKey 权限,可以将下面一行删除
// AV.Cloud.useMasterKey();
var app = require('./app');
// 端口一定要从环境变量 `LEANCLOUD_APP_PORT` 中获取。
// LeanEngine 运行时会分配端口并赋值到该变量。
var PORT = parseInt(process.env.LEANCLOUD_APP_PORT || process.env.PORT || 3000);
process.env.TZ = 'Asia/Chongqing';
app.listen(PORT, function (err) {
console.log('Node app is running on port:', PORT);
var workerpool = require('workerpool');
var bodyParser = require('body-parser');
var AV = require('leanengine');
var TextMessage = require('leancloud-realtime').TextMessage;
var app = express();
app.use(bodyParser.json());
var pool = workerpool.pool(__dirname + '/math_worker.js');
var TIMEOUT = 10000; // milliseconds
var APP_ID = process.env.LC_APP_ID; // your app id
var APP_KEY = process.env.LC_APP_KEY; // your app key
var MASTER_KEY = process.env.LC_APP_MASTER_KEY; // your app master key
AV.init({
'appId': APP_ID,
'appKey': APP_KEY,
'masterKey': MASTER_KEY
});
var MATH_CONV_ID = process.env.MATH_CONV_ID;
app.post('/webhook', function (req, res) {
var messages = req.body;
console.log('messages recieved: ' + JSON.stringify(messages));
// 过滤掉暂态消息与非通过 MathBot 对话发过来的消息
messages
.filter(message => !message.noPersist)
.filter(message => message.conv.objectId === MATH_CONV_ID)
.forEach(function (message) {
var convId = message.conv.objectId;
'use strict';
var AV = require('leanengine');
AV.init({
appId: process.env.LEANCLOUD_APP_ID,
appKey: process.env.LEANCLOUD_APP_KEY,
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY
});
AV.Cloud.useMasterKey();
var app = require('./app');
// 端口一定要从环境变量 `LEANCLOUD_APP_PORT` 中获取。
// LeanEngine 运行时会分配端口并赋值到该变量。
var PORT = parseInt(process.env.LEANCLOUD_APP_PORT || process.env.PORT || 3000);
app.listen(PORT, function (err) {
console.log('Node app is running on port:', PORT);
// 注册全局未捕获异常处理器
const authData = user.get('authData');
if (!authData || !authData.lc_weapp) {
return response.error(new Error('当前用户不是小程序用户'));
}
const order = new Order();
order.tradeId = uuid().replace(/-/g, '');
order.status = 'INIT';
order.user = request.currentUser;
order.productDescription = 'LeanCloud-小程序支付测试';
order.amount = 1;
order.ip = request.meta.remoteAddress;
if (!(order.ip && /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(order.ip))) {
order.ip = '127.0.0.1';
}
order.tradeType = 'JSAPI';
const acl = new AV.ACL();
// 只有创建订单的用户可以读,没有人可以写
acl.setPublicReadAccess(false);
acl.setPublicWriteAccess(false);
acl.setReadAccess(user, true);
acl.setWriteAccess(user, false);
order.setACL(acl);
order.place().then(() => {
console.log(`预订单创建成功:订单号 [${order.tradeId}] prepayId [${order.prepayId}]`);
const payload = {
appId: process.env.WEIXIN_APPID,
timeStamp: String(Math.floor(Date.now() / 1000)),
package: `prepay_id=${order.prepayId}`,
signType: 'MD5',
nonceStr: String(Math.random()),
}
payload.paySign = wxpay.sign(payload);
let ip = currentComment.get('ip') || defaultIp;
console.log('IP: %s', ip);
spam.checkSpam(currentComment, ip);
// AT评论通知
let rid =currentComment.get('pid') || currentComment.get('rid');
if (!rid) {
console.log("这条评论没有 @ 任何人");
return;
} else if (currentComment.get('isSpam')) {
console.log('评论未通过审核,通知邮件暂不发送');
return;
}
let query = new AV.Query('Comment');
query.get(rid).then(function (parentComment) {
if (parentComment.get('mail') && parentComment.get('mail') !== process.env.BLOGGER_EMAIL) {
mail.send(currentComment, parentComment);
} else {
console.log('被@者匿名,不会发送通知');
}
}, function (error) {
console.warn('获取@对象失败!');
});
}
const express = require('express')
const AV = require('leanengine')
const axios = require('axios')
const path = require('path')
AV.init({
appId: process.env.LEANCLOUD_APP_ID || 'Cct4URhkJo6VKYACsR3MklFt-gzGzoHsz',
appKey: process.env.LEANCLOUD_APP_KEY || 'BeJzllYAryhOzoNX0piav8tw',
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY || 'U5jcAlilltDr1vJmyfwIqC2D'
})
const app = express()
app.use(AV.express())
app.use(express.static(path.resolve(__dirname, './dist')))
const V2EX_BASE_URL = 'https://www.v2ex.com/api'
// v2ex topic info
app.get('/news/v2ex/topics/show.json?', function (req, response) {
let url = ''
if (req.query.id) {
const id = req.query.id
url = `${V2EX_BASE_URL}/topics/show.json?id=${id}`
axios.get(url).then(res => {
response.send(res.data[0])
})
} else if (req.query['node_name']) {
const contentType = req.query['node_name']
url = `${V2EX_BASE_URL}/topics/show.json?node_name=${contentType}`
Lean.init({
appId: process.env.LEANCLOUD_APP_ID,
appKey: process.env.LEANCLOUD_APP_KEY,
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY
})
// 如果不希望使用 masterKey 权限,可以删除
Lean.Cloud.useMasterKey()
// Init Express App
const app = express()
// Middlewares and Routes
app.use(express.static('dist'))
app.use(timeout('15s'))
app.use(Lean.express())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(uncaughtException)
app.all('/api/*', CORS)
// APIs setup
app.use('/api', API)
// Error handlers
app.use(errorHandler)
app.use(notFound)
// 端口一定要从环境变量 `LEANCLOUD_APP_PORT` 中获取。
// LeanEngine 运行时会分配端口并赋值到该变量。
const PORT = parseInt(process.env.LEANCLOUD_APP_PORT || 3000)