-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.js
89 lines (81 loc) · 2.61 KB
/
app.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict'
const express = require('express');
const cors = require('cors');
const app = express();
const http = require('http');
const amqp = require('amqplib/callback_api');
const amqpManager = require('amqp-connection-manager');
const unsafe = express.Router();
const bodyParser = require('body-parser');
const env = process.env;
const fs = require('fs');
const url = env.CONFIG_URL;
const errorHandling = require('../core/helpers/errorHandling');
const request = require('request');
const configJson = require('./config.json')
http.globalAgent.maxSockets = 1000000000
app.use(cors())
app.use(bodyParser.json({
limit: '100mb'
}))
app.use(bodyParser.urlencoded({
limit: '100mb',
extended: true
}))
unsafe.use(bodyParser.json())
const content = 'module.exports = ' + JSON.stringify(configJson)
fs.writeFile('configuration.js', content, 'utf8', function(err) {
if (err) {
throw err
} else {
console.log(configJson);
let connection = amqpManager.connect([(configJson.socketServerEngine ? configJson.socketServerEngine : configJson.socketServer) + '/' + configJson.amqpHost]);
let communication= require('./communication');
var channelWrapper = connection.createChannel({
json: true,
setup: function(channel) {
console.log("AMQP Connection");
onConnect(channel);
return Promise.all([
channel.assertQueue('work-ask', { durable: true }),
]);
// `channel` here is a regular amqplib `ConfirmChannel`.
// Note that `this` here is the channelWrapper instance.
// return channel.assertQueue('rxQueueName', {
// durable: true
// });
}
});
// amqp.connect((configJson.socketServerEngine ? configJson.socketServerEngine : configJson.socketServer) + '/' + configJson.amqpHost, (err, conn) => {
// conn.createChannel((_err, ch) => {
// ch.assertQueue('work-ask', {
// durable: true
// })
// onConnect(ch)
// })
// })
communication.setAmqpClient(channelWrapper)
const onConnect = (channel) => {
// console.log('ALLO');
communication.setAmqpChannel(channel);
// require('./amqpService')(unsafe, amqpClient)
}
app.use('/engine', unsafe)
communication.init(unsafe);
let port = process.env.APP_PORT || 8080;
app.listen(port, function(err) {
console.log("listen at port ", port)
})
app.use((_err, req, res, next) => {
if (_err) {
errorHandling(_err, res, next)
}
})
}
})
// console.log('url',url);
// request(url, {
// json: true
// }, (err, result, body) => {
// const configJson = result.body
// })