Total Complexity | 4 |
Complexity/F | 1.33 |
Lines of Code | 34 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | const express = require('express'); |
||
2 | |||
3 | const router = express.Router(); |
||
4 | |||
5 | router.get('/', (req, res) => { |
||
6 | const streamId = Math.random().toString(36).substring(2); |
||
7 | res.redirect(`/${streamId}`); |
||
8 | }); |
||
9 | |||
10 | router.get('/:streamId?', (req, res) => { |
||
11 | res.render('index', { |
||
12 | hostName: global.APP_HOST_NAME, |
||
13 | host: global.APP_HOST, |
||
14 | port: global.APP_PORT_FOR_HELP_BLOCK, |
||
15 | socketIoJs: global.APP_SOCKET_IO_JS, |
||
16 | streamId: req.params.streamId, |
||
17 | }); |
||
18 | }); |
||
19 | |||
20 | router.post('/:streamId?', (req, res) => { |
||
21 | const ip = req.headers['x-forwarded-for'] |
||
22 | || req.connection.remoteAddress |
||
23 | || req.socket.remoteAddress |
||
24 | || req.connection.socket.remoteAddress; |
||
25 | |||
26 | if (req.headers['content-type'] === 'application/json') { |
||
27 | global.socket.emit('log', { |
||
28 | streamId: req.params.streamId, format: 'json', data: req.body, ip, |
||
29 | }); |
||
30 | } |
||
31 | res.send(''); |
||
32 | }); |
||
33 | |||
34 | module.exports = router; |
||
35 |