-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
64 lines (48 loc) · 1.65 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
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
const express = require('express');
var router = express.Router();
const dotenv = require('dotenv').config();
const app = express();
const parser = require('./modules/chunkParser');
const connect = require('./RabbitMQ/publisher');
const consul = require('./consul/consul');
consul.register();
app.get("/queue", function (req, res) {
res.writeHead(200, { 'Content-Type': 'text plain' });
res.write('Work in progress');
res.end();
});
app.post("/", function (req, res) {
try {
req.on('data', function (chunk) {
const res = parser.cleanJSONObject(chunk);
console.log(res)
res.then(result => connect.connect(result));
});
res.writeHead(200, { 'Content-Type': 'text plain' });
res.write('Sucessful commit');
res.end();
} catch (err) {
console.log(err);
}
});
app.get('/test', (req, res) => {
res.send({ hello: 'world' });
});
// app.post("/healthcheck", function(req, res){
// let a = consul.serviceId;
// consul.healthcheck(consul.serviceId);
// res.writeHead(200, { 'Content-Type': 'text plain' });
// res.write('Sucessful test health');
// res.end();
// });
app.post("/unregister", function(req, res){
consul.unregister(consul.serviceId);
res.writeHead(200, { 'Content-Type': 'text plain' });
res.write('Sucessful unregistred');
res.end();
});
var swaggerUi = require('swagger-ui-express'),
swaggerDocument = require('./swagger.json');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/api/v1', router);
app.listen(4666, () => console.log("Service listening on port 4666"));