-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (33 loc) · 1.03 KB
/
server.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
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors')
const app = express();
const busboy = require('connect-busboy');
const { compression, decompression } = require('./algorithm');
const { processRequest } = require('./file-reader');
app.use(cors());
app.use(bodyParser.json());
app.use(busboy());
app.post('/compress', (req, res) => {
if (req.body.data) {
const { stringValue } = req.body.data;
const data = stringValue.split(',');
const compressed = compression(data);
return res.status(200).json({ data: compressed })
} else {
return processRequest(req, res, compression);
}
});
app.post('/decompress', (req, res) => {
if (req.body.data) {
const { stringValue } = req.body.data;
const data = stringValue.split(',');
const decompressed = decompression(data);
return res.status(200).json({ data: decompressed });
} else {
processRequest(req, res, decompression);
}
});
app.listen(9000, () => {
console.log('Server running on port 9000');
});