From 5dc9b9625b8191536c3ffe64c4a647e2eabf287f Mon Sep 17 00:00:00 2001 From: elpla Date: Tue, 2 May 2023 21:04:03 +0200 Subject: [PATCH] cambios server.ts --- restapi/cert.pem | 34 +++++++++++++ restapi/key.pem | 118 ++++++++++++++++++++++++++++++++++++++++++++++ restapi/server.ts | 14 +++++- 3 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 restapi/cert.pem create mode 100644 restapi/key.pem diff --git a/restapi/cert.pem b/restapi/cert.pem new file mode 100644 index 0000000..e0b71d4 --- /dev/null +++ b/restapi/cert.pem @@ -0,0 +1,34 @@ +-----BEGIN CERTIFICATE----- +MIIF7zCCA9egAwIBAgIUdRhkM61U0LX+Sldqc37mGADJPzMwDQYJKoZIhvcNAQEL +BQAwgYYxCzAJBgNVBAYTAlhYMRIwEAYDVQQIDAlTdGF0ZU5hbWUxETAPBgNVBAcM +CENpdHlOYW1lMRQwEgYDVQQKDAtDb21wYW55TmFtZTEbMBkGA1UECwwSQ29tcGFu +eVNlY3Rpb25OYW1lMR0wGwYDVQQDDBRDb21tb25OYW1lT3JIb3N0bmFtZTAeFw0y +MzA1MDIxNzI0MzNaFw0zMzA0MjkxNzI0MzNaMIGGMQswCQYDVQQGEwJYWDESMBAG +A1UECAwJU3RhdGVOYW1lMREwDwYDVQQHDAhDaXR5TmFtZTEUMBIGA1UECgwLQ29t +cGFueU5hbWUxGzAZBgNVBAsMEkNvbXBhbnlTZWN0aW9uTmFtZTEdMBsGA1UEAwwU +Q29tbW9uTmFtZU9ySG9zdG5hbWUwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIK +AoICAQC2RJca0OKwWfcFwGfHRvUEMhxCMjRlerMQiZRy4oidGJRpiEAQkqwn5LYd +9wpIWx+j/h6gl4unZUaORUcmb6qwLc0DhcoWlNajKb1KPAj5q4nX96gsuvaV8UvF +BEkwSpqIH76On5pmBhhL66sn/N9a9IPj53Hij1lr5465WZM5cqLjVSJ7BYNHlcyl +neHCXa/bwgm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5UyoTR1uFfZlynr3sn60P +d57UNjr4e3MUrfy5LGcfWJ4VomxUQ8pRR3PE/uiHqwHQqB6/fYMwV9UbbjWnx1ln +Gx8gwwIv9RMP1Ois7if/k4uthZIRY7Cd7XK+eke+CIje9cTSrbM9uefaKOI1zGF/ +k7PWHroI9Bc/c9TSB+6vcpuOUzgupf2i4IlfznXF/8LRPK6HB+jvF3PIqFNS87HM +nW5OarWs2i51vRoVIIxH4OlZtZwwtQe3iz+OfPNvTMh1cAU= +-----END CERTIFICATE----- \ No newline at end of file diff --git a/restapi/key.pem b/restapi/key.pem new file mode 100644 index 0000000..c91bc8f --- /dev/null +++ b/restapi/key.pem @@ -0,0 +1,118 @@ +-----BEGIN PRIVATE KEY----- +MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQC2RJca0OKwWfcF +wGfHRvUEMhxCMjRlerMQiZRy4oidGJRpiEAQkqwn5LYd9wpIWx+j/h6gl4unZUaO +RUcmb6qwLc0DhcoWlNajKb1KPAj5q4nX96gsuvaV8UvFBEkwSpqIH76On5pmBhhL +66sn/N9a9IPj53Hij1lr5465WZM5cqLjVSJ7BYNHlcylneHCXa/bwgmcFM2mL4pY +Guvo2WuxzECtUaFIAnNeqoIhLIE4SBazpNZRf4raCSwQ8fSdw60ogrPNJyu17aXB +/OPb0iPslOuqj711ShSeh+OT7RwoCoUua1tTqAOOYUgTOI6y3UxjzI50a9KKvGmz +X9fwprpx2q1QBhaWsac5PDVSHRMXiQod/z1Gz92dZjJOljtfdUxcp1ZHhVNl6cMa +RpCTFVQ70H9ete5Fi5X+OHeGiMoRghux2NfbiuUeGgJ4v2o0JvWLJ23x4YmcFDRT +ZXaX09HivgKSY3HE4qvrGvFh6s9rgvwnPx6Jl03zMoboBlNXEyyFCA7SL5prN3AH +s+SU4nA+1leBUXzAZTln82wcXKQOYQiB2y9QeLGKJa0a2SsSrdfhpL2qYvmf5slk +uyyXlxY3QsOEijgH4I1PTkN/lgFdj824FmeN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cFHsLXFJMoeikVGum/RP2x1AR +r6H5AoIBAHKhX73pV9xSvBo7ZVuSrvnloXhNGryUMpaIGc2lODw3HUeXHbFGVsBp +sDHhRH7XUObJGpMiSzfriQp+K0kvYro5pdZPZgOiw2MNqI96YGpWs/lI4KblJWtt +ZrPXe6paTioynV6FbOgcVTODyPzr8uNqjxQzubSbJsLi7Glp314ybLkBPKEImPLE +p+nvMi/8ppz2cnQlcwWGVAcfvPjaAbYDBvOOL/FHPq8uvvB4ENx4KcAPDup3LSu9 +moKvhrFxVrLlITWEfr6Ty9Q4tUo5dLt2hou41tGAtTyhUvrzRANWzLPcnbj6/ZEu +/cPAwf+HdRDs84F0y7ijxR6FKv15Feg= +-----END PRIVATE KEY----- +azureuser@DespliegeASWes3c:/etc/nginx$ ^C +azureuser@DespliegeASWes3c:/etc/nginx$ sudo cat key.pem ^C +azureuser@DespliegeASWes3c:/etc/nginx$ ls +cert.pem fastcgi.conf koi-utf modules-available proxy_params sites-enabled win-utf +conf.d fastcgi_params koi-win modules-enabled scgi_params snippets +csr.pem key.pem mime.types nginx.conf sites-available uwsgi_params +azureuser@DespliegeASWes3c:/etc/nginx$ nano nginx.conf +azureuser@DespliegeASWes3c:/etc/nginx$ sudo cat cert.pem +-----BEGIN CERTIFICATE----- +azureuser@DespliegeASWes3c:/etc/nginx$ ls +cert.pem fastcgi.conf koi-utf modules-available proxy_params sites-enabled win-utf +conf.d fastcgi_params koi-win modules-enabled scgi_params snippets +csr.pem key.pem mime.types nginx.conf sites-available uwsgi_params +azureuser@DespliegeASWes3c:/etc/nginx$ sudo cat key.pem +-----BEGIN PRIVATE KEY----- +MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQC2RJca0OKwWfcF +wGfHRvUEMhxCMjRlerMQiZRy4oidGJRpiEAQkqwn5LYd9wpIWx+j/h6gl4unZUaO +RUcmb6qwLc0DhcoWlNajKb1KPAj5q4nX96gsuvaV8UvFBEkwSpqIH76On5pmBhhL +66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QJcbo/YcEzcJdcuG90f8tBCVdhj/4WOjsb0PnlZmnLZrrHIe +mAp6+NFu8HW5L/A8HBaWsddf4mkeQhpmgGFBgp6luFWcgwzxrudsCuvTHfgbRsgy +gy8753Yyz16xDJFdwiUGgvH3FY71uFqXPf+vdW3XAoIBAQCdYBeiFARFMWkiqf3V ++iI1a6AECR9mK8HIaoW3E54wIZhuNxo+GbXa4KTUirvNauqqJjW09QXB5eNGIU9c +1g7eMMSQz++tc38yKtAzDt4Re8i+p/XVbj+NE0BmTvFUSEtG+xgXoRzoN2Q2Wosb +b1EODZfjeRLPH6rpDvLpSJvBdF+MgG9ESFCgF2pOcRUmLAPW6oE/Pg1TxB76JwhS +sAMnWiokmNDuQCZNJB1JRZ+HmgyJV40pU1Xjwc4I71FLr931RmulWg/0gl6Rwd+Z +JLbBwdIr3Z0VgzLcZkklBxB7MtTcXIm3nvEoZ8rcFHsLXFJMoeikVGum/RP2x1AR +r6H5AoIBAHKhX73pV9xSvBo7ZVuSrvnloXhNGryUMpaIGc2lODw3HUeXHbFGVsBp +sDHhRH7XUObJGpMiSzfriQp+K0kvYro5pdZPZgOiw2MNqI96YGpWs/lI4KblJWtt +ZrPXe6paTioynV6FbOgcVTODyPzr8uNqjxQzubSbJsLi7Glp314ybLkBPKEImPLE +p+nvMi/8ppz2cnQlcwWGVAcfvPjaAbYDBvOOL/FHPq8uvvB4ENx4KcAPDup3LSu9 +moKvhrFxVrLlITWEfr6Ty9Q4tUo5dLt2hou41tGAtTyhUvrzRANWzLPcnbj6/ZEu +/cPAwf+HdRDs84F0y7ijxR6FKv15Feg= +-----END PRIVATE KEY----- \ No newline at end of file diff --git a/restapi/server.ts b/restapi/server.ts index faeeb7d..5526d27 100644 --- a/restapi/server.ts +++ b/restapi/server.ts @@ -16,16 +16,26 @@ const httpsPort = 5001; const metricsMiddleware:RequestHandler = promBundle({includeMethod: true}); app.use(metricsMiddleware); +app.disable("x-powered-by"); + app.use(cors()); app.use(bp.json()); app.use("/api", api) const options = { - key: fs.readFileSync(process.env.SSL_PRIVKEY), - cert: fs.readFileSync(process.env.SSL_CERT) + key: fs.readFileSync('./key.pem'), + cert: fs.readFileSync('./cert.pem') }; + app.use((req, res, next) => { + if (req.secure) { + next(); + } else { + res.redirect(`https://${req.headers.host}${req.url}`); + } + }); + https.createServer(options, app).listen(httpsPort, () => { console.log(`Restapi server started on port ${httpsPort}`); }).on("error", (error: Error) => {