-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
83 lines (68 loc) · 1.93 KB
/
Copy pathapp.js
File metadata and controls
83 lines (68 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const express = require("express")
const bodyParser = require("body-parser")
const path = require("path")
const fs = require("fs")
const feishu = require("./feishuWebhook")
const app = express()
// https://stackabuse.com/get-http-post-body-in-express-js/
app.use(bodyParser.urlencoded({ extended: true }))
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"))
})
app.get("/release", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"))
})
app.get("/logo", (req, res) => {
const logo = path.join(__dirname, "logo.png")
const content = fs.readFileSync(logo, {
encoding: "base64",
})
res.set("Content-Type", "image/png")
res.send(Buffer.from(content, "base64"))
res.status(200).end()
})
app.get("/user", (req, res) => {
res.send([
{
title: "serverless framework",
link: "https://serverless.com",
},
])
})
app.get("/user/:id", (req, res) => {
const id = req.params.id
res.send({
id: id,
title: "serverless framework",
link: "https://serverless.com",
})
})
app.get("/404", (req, res) => {
res.status(404).send("Not found")
})
app.get("/500", (req, res) => {
res.status(500).send("Server Error")
})
// Error handler
app.use(function (err, req, res, next) {
console.error(err)
console.log(req)
console.log(next)
res.status(500).send("Internal Serverless Error")
})
app.post("/feishu", (req, res) => {
feishu.forwardMessageFeishu(req, res)
})
app.post("/release/feishu", (req, res) => {
feishu.forwardMessageFeishu(req, res)
})
app.get("/feishu", (req, res) => {
res.status(200).send({ tip: "You should use the post request, see doc: https://githubbot.ahaclub.net" })
})
app.get("/release/feishu", (req, res) => {
res.status(200).send({ tip: "You should use the post request, see doc: https://githubbot.ahaclub.net" })
})
// Web 类型云函数,只能监听 9000 端口
app.listen(9000, () => {
console.log("Server start on http://localhost:9000")
})