Skip to content

Commit

Permalink
update server, no token in source code
Browse files Browse the repository at this point in the history
  • Loading branch information
KE.HAO.CHANG 張格豪 authored and KE.HAO.CHANG 張格豪 committed Apr 24, 2020
1 parent 75ecd40 commit 1649b90
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ ui2/backend/config.js
ssl_auth_files/certrequest.csr
ssl_auth_files/pillaAuth-cert.pem
ssl_auth_files/pillaAuth-key.pem
server/.env
2 changes: 1 addition & 1 deletion linebot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "PORT=5001 bottender dev",
"dev": "bottender dev",
"lint": "eslint . ",
"start": "bottender start",
"test": "jest"
Expand Down
15 changes: 15 additions & 0 deletions server/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "node",
"program": "${workspaceFolder}/index.js",
"skipFiles": ["<node_internals>/**"]
}
]
}
16 changes: 11 additions & 5 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ const morgan = require("morgan");
const axios = require("axios");
const config = require("../config");
const { SlackOAuthClient } = require("messaging-api-slack");
require("dotenv").config();

const slackClient = SlackOAuthClient.connect(
"xoxb-1082926328692-1089407482497-XJENYGhYIJQrZRndVDGrk1aZ"
);
const slackClient = SlackOAuthClient.connect(process.env.SLACK_ACCESS_TOKEN);

const https_options = {
key: fs.readFileSync("./ssl_files/server_private_key.pem"),
Expand All @@ -22,18 +21,25 @@ const https_options = {

app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.text());
app.use(bodyParser.json());
app.use(morgan("dev"));

app.get("/version", (req, res) => {
res.send(config.serverVersion);
});

app.post("/module/offline", (req, res) => {
slackClient.postMessage("#statusreport", req.body);
// slackClient.postMessage("#statusreport", req.body);
res.sendStatus(200);
});

app.post("/forslack", (req, res) => {
// slackClient.postMessage("#statusreport", req.body);
// res.status(200).send(req.body.challenge.toString());
let str = req.body.challenge.toString();
res.send(str);
});

http.createServer(app).listen(config.serverPort, () => {
console.log("cake vending server listening on port " + config.serverPort);
});
Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"messaging-api-line": "^0.8.5",
"messaging-api-slack": "^0.8.2",
Expand Down
2 changes: 2 additions & 0 deletions ui2/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const config = require("../../config");
const sqlite3 = require("sqlite3").verbose();
const os = require("os");

//todo: idle的時候每五分鐘回抽

const mqttOpt = {
port: config.mqttBrokerPort,
clientId: config.backendVersion,
Expand Down

0 comments on commit 1649b90

Please sign in to comment.