-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (44 loc) · 1.57 KB
/
index.js
File metadata and controls
49 lines (44 loc) · 1.57 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
const express = require('express')
const app = express()
const http = require('http').Server(app)
const pug = require('pug')
const io = require('socket.io')(http)
const port = process.env.PORT || 8080
const bodyParser = require('body-parser')
const request = require('request')
// parse forms
app.use(bodyParser.urlencoded({ extended: true }))
// parse application/json
app.use(bodyParser.json())
// parse an HTML body into a string
app.use(bodyParser.text())
// parse some custom thing into a Buffer
app.use(bodyParser.raw())
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
io.on('connection', function (socket) {
console.log('a user connected')
io.emit('server_running', `http://localhost:${port}`)
})
app.all('/*', function ({ method, path, headers, body, ...req }, res) {
io.emit('new')
io.emit('outcome', { method, path, headers, body })
request({
method,
url: 'http://calapi.inadiutorium.cz/' + path
},
(err, response, body) => {
io.emit('income', { response: response.statusCode, headers: response.headers, body })
res.writeHead(response.statusCode, response.header)
res.write(body)
res.end()
// res.send(body)
})
// request[method.toLowerCase()]({ url:'http://calapi.inadiutorium.cz/' + path }, (err, response, body) => {
// console.log(err)
// io.emit('income', { response: response.statusCode, header: response.header, body })
// res.writeHead(response.statusCode, response.header)
// res.send(body)
// })
})
http.listen(port, () => console.log(`Example app listening on port ${port}!`))