84 lines
1.9 KiB
JavaScript
84 lines
1.9 KiB
JavaScript
const express = require("express");
|
|
const https = require('https');
|
|
const fs = require('fs');
|
|
const axios = require('axios');
|
|
const ejs = require("ejs");
|
|
const path = require("path");
|
|
const qrcode = require("qrcode");
|
|
const exp = require("constants");
|
|
|
|
const html5QrcodeScanner = require("html5-qrcode");
|
|
|
|
const { DCC } = require('dcc-utils/src');
|
|
|
|
const app = express();
|
|
const port = process.env.port || 3000;
|
|
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: false }));
|
|
|
|
app.set("view engine", "ejs");
|
|
app.set("views", path.join(__dirname, "view"));
|
|
|
|
app.use(express.static("public"));
|
|
|
|
app.get("/", (req, res, next) => {
|
|
res.render("index");
|
|
});
|
|
|
|
app.post("/scan", (req, res, next) => {
|
|
|
|
const input_text = req.body.cert;
|
|
|
|
DCC.fromRaw(input_text).then((dcc) => {
|
|
console.log(dcc.payload)
|
|
//console.log(dcc.raw)
|
|
res.status(200);
|
|
res.send(dcc.payload);
|
|
|
|
|
|
//console.log(dcc);
|
|
})
|
|
.catch(error =>{
|
|
res.status(500);
|
|
res.send('Error: invalid data');
|
|
});
|
|
});
|
|
app.post("/sendc19", (req, res, next) => {
|
|
|
|
const output_text = req.body.contenuto;
|
|
console.log(output_text);
|
|
const optionsf2 = {
|
|
method: 'POST',
|
|
// mode: 'no-cors',
|
|
body: output_text,
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
};
|
|
|
|
axios
|
|
.post('https://ufficio.egalware.com/GPW/Api/api/VC19', output_text)
|
|
.then(res => {
|
|
console.log(`statusCode: ${res.status}`)
|
|
console.log(res)
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
})
|
|
res.status(200);
|
|
|
|
res.send('Recorded');
|
|
|
|
});
|
|
https.createServer({
|
|
key: fs.readFileSync('privkey.pem'),
|
|
cert: fs.readFileSync('fullchain.pem')
|
|
}, app)
|
|
.listen(port, function () {
|
|
console.log('Example app listening on port 3000! Go to https://localhost:3000/')
|
|
})
|
|
//app.listen(port, console.log(`Listening on port ${port}`));
|