forked from line/line-liff-v2-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·45 lines (37 loc) · 1.1 KB
/
index.js
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
const { execSync } = require('child_process');
const express = require('express');
const ngrok = require("ngrok");
const app = express();
const port = process.env.PORT || 8080;
const BEARER = process.env.BEARER;
const MY_LIFF_ID = process.env.MY_LIFF_ID;
app.use(express.urlencoded({
extended: true
}));
app.use(express.json());
app.use(express.static('public'));
app.set('view engine', 'ejs');
app.use("/", require("./routes/index"))
if (process.env.NODE_ENV == "pure") {
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
} else {
ngrok.connect(port).then((url) => {
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
console.log(`Example app listening at ${url}`);
const shell = `curl -XPUT \
-H "Authorization: Bearer ${BEARER}" \
-H "Content-Type: application/json" \
-d '{
"view": {
"type": "full",
"url": "${url}"
}
}' \
https://api.line.me/liff/v2/apps/${MY_LIFF_ID}`
execSync(shell)
});
})
}