-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShadowServer.js
43 lines (38 loc) · 895 Bytes
/
ShadowServer.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
var http = require( 'http' );
/**
* Redirect from http port 80 to https
* Try http://domain.com/README.md
*/
class ShadowServer
{
constructor( port = 80 )
{
super();
this.$port = port;
this.$server = http.createServer( this.$onRequest )
.listen( port, this.$onLoad );
}
$onRequest( request, response )
{
console.log( 'Will redirect to:', "https://" + request.headers[ 'host' ] + request.url )
response.writeHead( 301,
{
"Location": "https://" + request.headers[ 'host' ] + request.url
}
);
response.end();
}
$onLoad()
{
console.log( 'Shadow server running on port `this.Port`.' );
}
get port()
{
return this.$port;
}
get server()
{
return this.$server;
}
}
module.export = ShadowServer;