Ajout gestion Look & Sync firmwares, et routes BST
This commit is contained in:
32
app.js
32
app.js
@@ -10,6 +10,8 @@ const https = require('https');
|
||||
const certificate = fs.readFileSync(process.env.CLIENT_CRT || 'cert/client.crt', 'utf8');
|
||||
const privateKey = fs.readFileSync(process.env.CLIENT_KEY || 'cert/client.key', 'utf8');
|
||||
|
||||
const firmwares = './resources/firmwares/'
|
||||
|
||||
const credentials = {
|
||||
key: privateKey,
|
||||
cert: certificate,
|
||||
@@ -18,6 +20,7 @@ const credentials = {
|
||||
};
|
||||
|
||||
const dbcontroller = require('./db');
|
||||
const {firmware} = require('./services');
|
||||
const routes = require('./routes')
|
||||
|
||||
const app = express();
|
||||
@@ -39,6 +42,12 @@ console.log(' T E C H N O L O G I E S');
|
||||
console.log('');
|
||||
console.log('');
|
||||
|
||||
firmware.init(firmwares)
|
||||
.then((err) => {
|
||||
if (err) { console.log('Unable to initialize firmware service')}
|
||||
else { console.log ('Firmware service initialized') }
|
||||
})
|
||||
|
||||
///// Startup MongoDB Client
|
||||
dbcontroller.init()
|
||||
.then((err) => {
|
||||
@@ -66,6 +75,10 @@ dbcontroller.init()
|
||||
console.log('HTTPS Port: ' + https_port);
|
||||
console.log('-------------------------------------------------------');
|
||||
});
|
||||
|
||||
///// Set keep-alive timeout
|
||||
httpServer.keepAliveTimeout = 120*1000;
|
||||
httpsServer.keepAliveTimeout = 120*1000;
|
||||
}
|
||||
})
|
||||
|
||||
@@ -81,7 +94,7 @@ app.use(function (req, res, next) {
|
||||
});
|
||||
|
||||
app.use(function (req, res, next) {
|
||||
if (!req.body.length) {
|
||||
if (!req.body) {
|
||||
// No body
|
||||
//////////
|
||||
console.log('Got empty frame');
|
||||
@@ -100,6 +113,9 @@ app.use(function (req, res, next) {
|
||||
cbor_length = req.body.length;
|
||||
///// Decode CBOR body
|
||||
cbor.decodeFirst(req.body, (err, decoded) => {
|
||||
///// Check for error
|
||||
if (err) { res.sendStatus(418); return; }
|
||||
|
||||
///// Assign decoded data
|
||||
req.body = decoded;
|
||||
json_length = JSON.stringify(decoded).length
|
||||
@@ -129,7 +145,19 @@ app.use(function (req, res, next) {
|
||||
/////////////////////////
|
||||
// Redefine send function
|
||||
res.send = function (body) {
|
||||
if (req.is('application/cbor') || req.acceptsEncodings("application/cbor") || req.acceptsEncodings("cbor")) {
|
||||
if (Buffer.isBuffer(body)) {
|
||||
// Octet/Stream frame
|
||||
/////////////////////
|
||||
|
||||
///// Set header
|
||||
res.set('Content-Type', 'application/octet-stream');
|
||||
|
||||
// Log statistics
|
||||
console.log('Stream:');
|
||||
console.log(body.toString('hex'))
|
||||
console.log(body.length + ' Bytes');
|
||||
|
||||
} else if (req.is('application/cbor') || req.acceptsEncodings("application/cbor") || req.acceptsEncodings("cbor")) {
|
||||
// CBOR Frame
|
||||
/////////////
|
||||
console.log('Send CBOR frame');
|
||||
|
||||
Reference in New Issue
Block a user