May 27, 2021 A minimalist getting started manual for cloud development serverless
1. Case 1: Article Reading Service
2. Case 2: Top of the University Program
We set up our own blogs, or personal websites, often requiring statistical services. S
tatistical services are divided into two kinds, one is similar to Baidu, AIA statistics, according to the data to see PV/UV or crowd portraits. B
ut sometimes it's also necessary to show the number of readings per article to the reader.
Reading statistics services can serve neither the latter nor themselves.
You can refer
to the serverless practice: Build your own reading count component in this
article.
The core code is as follows:
'use strict';
const tcb = require('tcb-admin-node')
const app = tcb.init({
env: "你的环境 ID"
})
const db = app.database()
const _ = db.command
exports.main = async (event, context) => {
let coll = "read_count"
let path = decodeURIComponent(event.queryStringParameters.path || '')
let host = decodeURIComponent(event.queryStringParameters.host || '')
if(!path && !host){
return {
status: 0,
info: '必须传入 host 和 path 参数'
}
}
let data = await db.collection(coll).where({
host: host,
path: path
}).limit(1).get()
//更新
if(data.data.length){
let doc_id = data.data[0]._id
await db.collection(coll).doc(doc_id).update({
count: _.inc(1)
})
let obj = await db.collection(coll).doc(doc_id).get()
return {
status: 1,
count: obj.data[0].count
}
}
//增加
else{
let o = await db.collection(coll).add({
host: host,
path: path,
count: 1
})
return {
status: 1,
count: 1
}
}
};
If you don't want to develop and build, but want to use out-of-the-https://github.com/serverless80/tongji, you can refer to reading https://github.com/serverless80/tongji, which is already deployed as a stand-alone service.
In 2018, a small program called "Top of the University" was developed that contains data from 2,600 plus colleges and universities;
You can sweep the code experience.
The effect of the small program is as follows:
Of course, the data for this little program is open source, https://github.com/vczero/serverless-colleage. W ith data, it's easy to use cloud development to build a small program.
There are a lot of good memories, there are a lot of important pictures, picture management is very difficult. M obile phones change one a year, picture transmission effort is often lost. O ften prompt that there is not enough space, delete it over and over again. S o idly come up with a small program: a small favorite to manage the private pictures you need to collect. Y ou can scan the experience:
The effect of the small program is as follows:
The code is already open source, please refer to: https://github.com/vczero/CloudPhoto.
Embrace Serverless, embrace cloud development, use the productivity of the times, do something interesting...