-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.dev.js
53 lines (41 loc) · 1.28 KB
/
server.dev.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
52
53
/*eslint no-console: 0*/
'use strict';
const app = require('./index');
const fs = require('fs')
, path = require('path')
, process = require('process')
;
const sslRootCas = require('ssl-root-cas').inject();
let client = require('http');
let port = process.env.PORT || 8000;
let protocol= 'http';
let server;
try{
const pfx = fs.readFileSync( process.env.pfx || 'no_certificate' );
const passphrase = process.env.passphrase || 'no_certificate';
if(pfx && passphrase){
client = require('https');
server = client.createServer({
pfx: pfx,
passphrase: passphrase
}, app);
protocol='https';
port = process.env.PORT || 8443;
}
}catch(e){ null; }
server = server || client.createServer(app);
/*
* Injection des certificats Authorité
*/
const certificatesDirectory=path.join(__dirname, '/ressources/certificates_authorite/');
let certificates=fs.readdirSync(certificatesDirectory);
for(let i=0, end=certificates.length; i<end; i++){
sslRootCas.addFile(path.join(certificatesDirectory,certificates[i]));
}
/*
* Create and start HTTP server.
*/
server.listen(port || 8000);
server.on('listening', function () {
console.log('Server listening on %s://localhost:%d', protocol, this.address().port);
});