⚠️ 前期使用 serverless 后端架构,代码量多了后改为完整 server 部署,所以本目录下代码逻辑可能不是最新。请先阅读 云函数文档 以了解云函数
云开发是一体化开发环境和工具平台,能够帮你快速开发后台应用
先在 官网 开通云开发,获得环境 id,然后将环境 id 填写到本项目根目录的 cloudbaserc.json
中。
请先阅读:云开发 CLI 工具文档
先安装云开发 CLI 工具
npm i -g @cloudbase/cli
本地测试
tcb fn run --name <functionName> --params "{\"userId\": 1}" --path <functionPath>
更新函数代码
tcb fn code update <functionName> --dir <functionPath>
部署函数代码
tcb fn deploy <functionName> --dir <functionPath>
涉及项目机密,仅对 星球内 同学公开
题目表 question_v1
GET question/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"name": ""
}
},
{
"match": {
"desc": ""
}
}
],
"filter": [
{
"term": {
"reviewStatus": 1
}
},
{
"term": {
"isDelete": false
}
},
{
"term": {
"tags": "java"
}
},
{
"term": {
"tags": "框架"
}
}
],
"minimum_should_match": 0
}
},
"from": 0,
"size": 5,
"_source": ["name", "_createTime", "desc", "reviewStatus", "priority", "tags"],
"sort": [
{
"priority": {
"order": "desc"
}
},
{
"_score": {
"order": "desc"
}
},
{
"publishTime": {
"order": "desc"
}
}
]
}
请阅读:一站式后端服务文档
tcb fn deploy esService --dir cloudfunctions/common/esService --force
tcb fn deploy sendEmail --dir cloudfunctions/common/sendEmail --force
tcb fn deploy redisService --dir cloudfunctions/common/redisService --force
tcb fn deploy addQuestion --dir cloudfunctions/question/addQuestion --force
tcb fn deploy addQuestionsToES --dir cloudfunctions/question/addQuestionsToES --force
tcb fn deploy syncQuestionsToES --dir cloudfunctions/question/syncQuestionsToES --force
tcb fn deploy deleteQuestion --dir cloudfunctions/question/deleteQuestion --force
tcb fn deploy favourQuestion --dir cloudfunctions/question/favourQuestion --force
tcb fn deploy reviewQuestion --dir cloudfunctions/question/reviewQuestion --force
tcb fn deploy searchQuestions --dir cloudfunctions/question/searchQuestions --force
tcb fn deploy getRandomQuestion --dir cloudfunctions/question/getRandomQuestion --force
tcb fn deploy shareQuestion --dir cloudfunctions/question/shareQuestion --force
tcb fn deploy updateQuestion --dir cloudfunctions/question/updateQuestion --force
tcb fn deploy viewQuestion --dir cloudfunctions/question/viewQuestion --force
tcb fn deploy listRecommendQuestions --dir cloudfunctions/question/listRecommendQuestions --force
tcb fn deploy getTagsMap --dir cloudfunctions/tag/getTagsMap --force
tcb fn deploy login --dir cloudfunctions/login --force
tcb fn deploy getUser --dir cloudfunctions/user/getUser --force
tcb fn deploy getCaptcha --dir cloudfunctions/getCaptcha --force
tcb fn deploy getSimpleUser --dir cloudfunctions/user/getSimpleUser --force
tcb fn deploy getCurrentUser --dir cloudfunctions/user/getCurrentUser --force
tcb fn deploy listUserCycleRank --dir cloudfunctions/user/listUserCycleRank --force
tcb fn deploy listUserTotalRank --dir cloudfunctions/user/listUserTotalRank --force
tcb fn deploy getUserRank --dir cloudfunctions/user/getUserRank --force
tcb fn deploy updateUser --dir cloudfunctions/user/updateUser --force
tcb fn deploy searchPapers --dir cloudfunctions/paper/searchPapers --force
tcb fn deploy addSearchHistory --dir cloudfunctions/searchHistory/addSearchHistory --force
tcb fn deploy hotSearches --dir cloudfunctions/searchHistory/hotSearches --force
tcb fn deploy addReport --dir cloudfunctions/report/addReport --force
tcb fn deploy reviewReport --dir cloudfunctions/report/reviewReport --force
tcb fn deploy addComment --dir cloudfunctions/comment/addComment --force
tcb fn deploy deleteComment --dir cloudfunctions/comment/deleteComment --force
tcb fn deploy updateComment --dir cloudfunctions/comment/updateComment --force
tcb fn deploy reviewComment --dir cloudfunctions/comment/reviewComment --force
tcb fn deploy searchComments --dir cloudfunctions/comment/searchComments --force
tcb fn deploy thumbUpComment --dir cloudfunctions/comment/thumbUpComment --force
tcb fn deploy addQuestionEdit --dir cloudfunctions/questionEdit/addQuestionEdit --force
tcb fn deploy deleteQuestionEdit --dir cloudfunctions/questionEdit/deleteQuestionEdit --force
tcb fn deploy updateQuestionEdit --dir cloudfunctions/questionEdit/updateQuestionEdit --force
tcb fn deploy reviewQuestionEdit --dir cloudfunctions/questionEdit/reviewQuestionEdit --force
tcb fn deploy searchQuestionEdits --dir cloudfunctions/questionEdit/searchQuestionEdits --force
tcb fn deploy addReply --dir cloudfunctions/reply/addReply --force
tcb fn deploy deleteReply --dir cloudfunctions/reply/deleteReply --force
tcb fn deploy searchReplies --dir cloudfunctions/reply/searchReplies --force
tcb fn deploy addMeetQuestion --dir cloudfunctions/meetQuestion/addMeetQuestion --force
tcb fn deploy deleteMeetQuestion --dir cloudfunctions/meetQuestion/deleteMeetQuestion --force
tcb fn deploy updateMeetQuestion --dir cloudfunctions/meetQuestion/updateMeetQuestion --force
tcb fn deploy searchMeetQuestions --dir cloudfunctions/meetQuestion/searchMeetQuestions --force
tcb fn deploy addPaper --dir cloudfunctions/paper/addPaper --force
tcb fn deploy viewPaper --dir cloudfunctions/paper/viewPaper --force
tcb fn deploy updatePaper --dir cloudfunctions/paper/updatePaper --force
tcb fn deploy deletePaper --dir cloudfunctions/paper/deletePaper --force
tcb fn deploy addMessage --dir cloudfunctions/message/addMessage --force
tcb fn deploy countMyMessages --dir cloudfunctions/message/countMyMessages --force
tcb fn deploy searchMessages --dir cloudfunctions/message/searchMessages --force
tcb fn deploy updateAllMessages --dir cloudfunctions/message/updateAllMessages --force
tcb fn deploy updateMessage --dir cloudfunctions/message/updateMessage --force
tcb fn deploy addUserScore --dir cloudfunctions/userScore/addUserScore --force
tcb fn deploy countUserScoreRank --dir cloudfunctions/userScore/countUserScoreRank --force
- 云函数事务
const transaction = await db.startTransaction();
try {
await xxx();
await xxx();
await transaction.commit();
return id;
} catch (e) {
console.error('xxx error', e);
await transaction.rollback();
return -1;
}