Ajout routes API PUT/DEL

This commit is contained in:
Arnaud Nelissen
2025-09-25 18:41:59 +02:00
parent 73add80cab
commit 3ff1b73cd2
5 changed files with 297 additions and 23 deletions

18
app.js
View File

@@ -7,6 +7,8 @@ const fs = require('fs');
const http = require('http');
const https = require('https');
require('dotenv').config()
const certificate = fs.readFileSync(process.env.CLIENT_CRT || 'cert/client.crt', 'utf8');
const privateKey = fs.readFileSync(process.env.CLIENT_KEY || 'cert/client.key', 'utf8');
@@ -115,15 +117,17 @@ app.use(function (req, res, next) {
cbor.decodeFirst(req.body, (err, decoded) => {
///// Check for error
if (err) { res.sendStatus(418); return; }
if (cbor_length > 0) {
///// Assign decoded data
req.body = decoded;
json_length = JSON.stringify(decoded).length
///// Assign decoded data
req.body = decoded;
json_length = JSON.stringify(decoded).length
///// Next handler
console.log('Decoded:');
console.log(req.body)
console.log(cbor_length + ' Bytes (CBOR) -> ' + json_length + ' Bytes (JSON) -> ' + Math.round((cbor_length / json_length - 1) * 100) + '% reduction');
}
///// Next handler
console.log('Decoded:');
console.log(req.body)
console.log(cbor_length + ' Bytes (CBOR) -> ' + json_length + ' Bytes (JSON) -> ' + Math.round((cbor_length / json_length - 1) * 100) + '% reduction');
next();
});