-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.js
51 lines (43 loc) · 1.68 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const express = require('express');
const fs = require('fs');
const https = require('https');
const logger = require('morgan');
const helmet = require('helmet');
const { constants } = require('crypto')
const multer = require('multer');
let formMulter = multer();
app = express();
const options = {
port: process.env.PORT || 3000,
address: process.env.LISTEN || '127.0.0.1',
use_ssl: process.env.USE_SSL || true,
keyPath: process.env.SSL_KEY || 'privkey.pem',
certPath: process.env.SSL_CERT || 'cert.pem',
caPath: process.env.SSL_CA || 'chain.pem',
logPath: process.env.LOG_PATH || '/var/log',
};
bodyParser = require('body-parser');
app.use(helmet());
if (options.logPath != "false") {
app.use(logger('combined',{stream: fs.createWriteStream(options.logPath+'/remote-pdf-printer.log')}));
} else {
app.use(logger('combined'));
}
app.use(bodyParser.urlencoded({limit: '10mb', extended: true }));
const pdfRoutes = require('./api/routes/printPdfRoutes');
const pngRoutes = require('./api/routes/printPngRoutes');
pdfRoutes(app, formMulter);
pngRoutes(app, formMulter);
if (options.use_ssl === true) {
console.log('USING SSL! KEY: '+options.keyPath+"\nCert: "+options.certPath+"\nPort: "+options.port);
https.createServer({
secureOptions: constants.SSL_OP_NO_TLSv1|constants.SSL_OP_NO_SSLv2|constants.SSL_OP_NO_SSLv3,
key: fs.readFileSync(options.keyPath),
cert: fs.readFileSync(options.certPath),
ca: [ fs.readFileSync(options.caPath)]
},app).listen(options.port,options.address);
} else {
console.log("**NOT** USING SSL! \nPort: "+options.port);
app.listen(options.port,options.address);
}
console.log('HTML to PDF RESTful API server started');