Skip to content

Instantly share code, notes, and snippets.

@chetbis
Last active August 6, 2019 16:45
Show Gist options
  • Save chetbis/bd92e3dc6ff13d640892aeca23596db7 to your computer and use it in GitHub Desktop.
Save chetbis/bd92e3dc6ff13d640892aeca23596db7 to your computer and use it in GitHub Desktop.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout cert.key -out cert.pem -config req.cnf -sha256
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));
[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