-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (46 loc) · 1.27 KB
/
server.js
File metadata and controls
55 lines (46 loc) · 1.27 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
const express = require('express');
const bodyParser = require('body-parser');
const huff = require('./utils/huffman');
const lzw = require('./utils/lzw');
// Initiate a instance of express.
const app = express();
const PORT = process.env.PORT || 3000;
// Make ./public the web root.
app.use(express.static('public'));
// Start
app.listen(PORT, () => console.log(`Server running on http://localhost:${PORT}....`));
// Get index.html as the base site
app.get('/', function (req, res) {
res.sendFile('index.html');
});
// Configuring the bodyParser middleware
app.use(
bodyParser.urlencoded({
limit: '100mb',
extended: true,
parameterLimit: 500000,
})
);
// DECODE
app.post('/decode', function (req, res) {
let encodedBits = req.body.bits;
let codingSchemeObject = req.body.obj;
let huffDecoded = huff.huffmanDecode(encodedBits, codingSchemeObject);
let lzwDecoded = lzw.lzwDecode(huffDecoded);
res.send(lzwDecoded);
});
// Configuring the bodyParser middleware
app.use(
bodyParser.urlencoded({
limit: '100mb',
extended: true,
parameterLimit: 500000,
})
);
// ENCODE
app.post('/encode', function (req, res) {
let inputString = req.body.string;
let lzwEncoded = lzw.lzwEncode(inputString);
let encodedObject = huff.huffmanEncode(lzwEncoded);
res.json(encodedObject);
});