-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e293f3
commit 8dc7977
Showing
8 changed files
with
5,437 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: deploy | ||
|
||
on: | ||
pull_requests: | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./ | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: mkdir -p /home/runner/.npm | ||
continue-on-error: true | ||
|
||
- name: Use Node.js 12 | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 12 | ||
cache: 'npm' | ||
cache-dependency-path: ./package-lock.json | ||
|
||
|
||
- name: npm install | ||
run: npm install | ||
- name: npm install serverless | ||
run: npm i -g serverless serverless-tencent | ||
- name: run eslint fix | ||
run: eslint "./**.js" --fix | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,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(); | ||
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.use(bodyParser.urlencoded({ extended: true })) | ||
|
||
app.get(`/`, (req, res) => { | ||
res.sendFile(path.join(__dirname, 'index.html')); | ||
}); | ||
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("/release", (req, res) => { | ||
res.sendFile(path.join(__dirname, "index.html")) | ||
}) | ||
|
||
app.get(`/logo`, (req, res) => { | ||
const logo = path.join(__dirname, 'logo.png'); | ||
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(); | ||
}); | ||
encoding: "base64", | ||
}) | ||
res.set("Content-Type", "image/png") | ||
res.send(Buffer.from(content, "base64")) | ||
res.status(200).end() | ||
}) | ||
|
||
app.get('/user', (req, res) => { | ||
app.get("/user", (req, res) => { | ||
res.send([ | ||
{ | ||
title: 'serverless framework', | ||
link: 'https://serverless.com', | ||
title: "serverless framework", | ||
link: "https://serverless.com", | ||
}, | ||
]); | ||
}); | ||
]) | ||
}) | ||
|
||
app.get('/user/:id', (req, res) => { | ||
const id = req.params.id; | ||
app.get("/user/:id", (req, res) => { | ||
const id = req.params.id | ||
res.send({ | ||
id: id, | ||
title: 'serverless framework', | ||
link: 'https://serverless.com', | ||
}); | ||
}); | ||
title: "serverless framework", | ||
link: "https://serverless.com", | ||
}) | ||
}) | ||
|
||
app.get('/404', (req, res) => { | ||
res.status(404).send('Not found'); | ||
}); | ||
app.get("/404", (req, res) => { | ||
res.status(404).send("Not found") | ||
}) | ||
|
||
app.get('/500', (req, res) => { | ||
res.status(500).send('Server Error'); | ||
}); | ||
app.get("/500", (req, res) => { | ||
res.status(500).send("Server Error") | ||
}) | ||
|
||
// Error handler | ||
app.use(function (err, req, res, next) { | ||
console.error(err); | ||
res.status(500).send('Internal Serverless Error'); | ||
}); | ||
console.error(err) | ||
console.log(req) | ||
console.log(next) | ||
res.status(500).send("Internal Serverless Error") | ||
}) | ||
|
||
// Web 类型云函数,只能监听 9000 端口 | ||
app.listen(9000, () => { | ||
console.log(`Server start on http://localhost:9000`); | ||
}); | ||
console.log("Server start on http://localhost:9000") | ||
}) | ||
|
||
|
||
app.post('/feishu', (req, res) => { | ||
app.post("/feishu", (req, res) => { | ||
feishu.forwardMessageFeishu(req, res) | ||
}); | ||
}) | ||
|
||
app.post(`/release/feishu`, (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("/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" }); | ||
}); | ||
app.get("/release/feishu", (req, res) => { | ||
res.status(200).send({ tip: "You should use the post request, see doc: https://githubbot.ahaclub.net" }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.