// Example of the server https is taken from here: https://engineering.circle.com/https-authorized-certs-with-node-js-315e548354a2 // Conversion of client1-crt.pem to certificate.pfx: https://stackoverflow.com/a/38408666/4637638 const express = require('express') const https = require('https') const cors = require('cors') const auth = require('basic-auth') const app = express() const appHttps = express() const appAuthBasic = express() const fs = require('fs') const path = require('path') var options = { key: fs.readFileSync('server-key.pem'), cert: fs.readFileSync('server-crt.pem'), ca: fs.readFileSync('ca-crt.pem'), requestCert: true, rejectUnauthorized: false }; appHttps.get('/', (req, res) => { console.log(JSON.stringify(req.headers)) const cert = req.connection.getPeerCertificate() // The `req.client.authorized` flag will be true if the certificate is valid and was issued by a CA we white-listed // earlier in `opts.ca`. We display the name of our user (CN = Common Name) and the name of the issuer, which is // `localhost`. if (req.client.authorized) { res.send(`
HELLO
`); res.end() }) app.post("/test-post", (req, res) => { console.log(JSON.stringify(req.headers)) console.log(JSON.stringify(req.body)) res.send(`HELLO ${req.body.name}!
`); res.end() }) app.post("/test-ajax-post", (req, res) => { console.log(JSON.stringify(req.headers)) console.log(JSON.stringify(req.body)) res.set("Content-Type", "application/json") res.send(JSON.stringify({ "firstname": req.body.firstname, "lastname": req.body.lastname, "fullname": req.body.firstname + " " + req.body.lastname, })) res.end() }) app.get("/test-download-file", (req, res) => { console.log(JSON.stringify(req.headers)) const filePath = path.join(__dirname, 'assets', 'flutter_logo.png'); const stat = fs.statSync(filePath); const file = fs.readFileSync(filePath, 'binary'); res.setHeader('Content-Length', stat.size); res.setHeader('Content-Type', 'image/png'); res.setHeader('Content-Disposition', 'attachment; filename=flutter_logo.png'); res.write(file, 'binary'); res.end(); }) app.listen(8082)