Last active
August 6, 2019 16:45
-
-
Save chetbis/bd92e3dc6ff13d640892aeca23596db7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout cert.key -out cert.pem -config req.cnf -sha256 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const httpStatusCodes = require('http-status-codes'); | |
const express = require('express'); | |
const request = require('request'); | |
const config = require('./config'); | |
const helmet = require('helmet'); | |
const https = require('https'); | |
const app = express(); | |
const fs = require('fs'); | |
const key = fs.readFileSync('./security/cert.key', 'utf-8'); | |
const cert = fs.readFileSync('./security/cert.pem', 'utf-8'); | |
const credentials = { key, cert }; | |
app.use(helmet()); | |
app.get('/getPdfDocument', (req, res) => { | |
const uri = req.query.uri; | |
if (uri) { | |
request({ | |
uri, | |
method: 'GET', | |
encoding: null | |
}, (err, response, body) => { | |
if (err) { | |
res.status(httpStatusCodes.INTERNAL_SERVER_ERROR).send({ message: 'Unable to get the file' }); | |
} else { | |
res.set(response.headers); | |
res.send(body); | |
} | |
}); | |
} else { | |
res.status(httpStatusCodes.BAD_REQUEST) | |
.send({ error: 'uri query parameter is missing' }); | |
} | |
}); | |
https.createServer(credentials, app).listen(config.PORT, () => console.log('server listening on port', config.PORT)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[req] | |
distinguished_name = req_distinguished_name | |
x509_extensions = v3_req | |
prompt = no | |
[req_distinguished_name] | |
C = Country initials like US, RO, GE | |
ST = State | |
L = Location | |
O = Organization Name | |
OU = Organizational Unit | |
CN = www.localhost.com | |
[v3_req] | |
keyUsage = critical, digitalSignature, keyAgreement | |
extendedKeyUsage = serverAuth | |
subjectAltName = @alt_names | |
[alt_names] | |
DNS.1 = www.localhost.com | |
DNS.2 = localhost.com | |
DNS.3 = localhost |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment