-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
67 lines (51 loc) · 1.56 KB
/
Copy pathapp.js
File metadata and controls
67 lines (51 loc) · 1.56 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
const https = require('https')
const fs = require('fs')
const request = require('request')
const options = {
// Private Key
key: fs.readFileSync('./ssl/server.key'),
// SSL Certficate
cert: fs.readFileSync('./ssl/server.crt'),
// Make sure an error is not emitted on connection when the server certificate verification against the list of supplied CAs fails.
rejectUnauthorized: false
}
const express = require('express')
const morgan = require('morgan')
const path = require('path')
const bodyParser = require('body-parser')
const cors = require('cors')
const qs = require('qs')
const app = express()
const port = 3000
const server = https.createServer(options, app).listen(port, () => {
console.log(`BookingBot.Web running at https://localhost:${port}`)
})
app.use(bodyParser.urlencoded({ extended: true}))
app.use(bodyParser.json());
app.use(cors());
app.use(morgan('combined'))
app.use(express.static(path.join(__dirname, 'public')))
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public/index.html'))
})
app.get('/authresponse', (req, res) => {
res.redirect(301, `/?${qs.stringify(req.query)}`);
})
app.get('/parse-m3u', (req, res) => {
const m3uUrl = req.query.url
console.log(m3uUrl)
if (!m3uUrl) {
return res.json([])
}
const urls = []
request(m3uUrl, function(error, response, bodyResponse) {
console.log(bodyResponse, m3uUrl)
if (bodyResponse) {
urls.push(bodyResponse)
}
res.json(urls)
})
})
app.use((req, res, next) => {
res.status(404).sendFile(path.join(__dirname, 'public/404.html'))
})