-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (44 loc) · 1.11 KB
/
index.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
var fs = require( 'fs' );
var ShadowServer = require( './ShadowServer.js' );
var restify = require( 'restify' );
// check arguments exist
if( process.env.SSL_CERT == null || process.env.SSL_KEY == null )
{
throw new Error(
"SSL certificate and key required! No env variables set. Abort."
);
}
// check files exist
if( !fs.existsSync( process.env.SSL_CERT ) || !fs.existsSync( process.env.SSL_KEY ) )
{
throw new Error(
"SSL certificate and key required! Could not find files. Abort."
);
}
//
// Setup Restify Server (HTTPS)
//
var server = restify.createServer({
name: 'node-ssl-test',
version: '1.0.0',
certificate: fs.readFileSync( process.env.SSL_CERT ),
key: fs.readFileSync( process.env.SSL_KEY )
});
/**
* Test server by serving local files
* Try https://domain.com/README.md
*/
server.get( /.*/, restify.plugins.serveStatic(
{
'directory': __dirname,
'default': 'index.html'
}));
server.listen( 443, function()
{
console.log( '%s listening to %s', server.name, server.url );
});
/**
* Redirect from http port 80 to https
* Try http://domain.com/README.md
*/
var shadowServer = new ShadowServer( 80 );