Skip to content

Commit f05ff4d

Browse files
committed
Add SSL Certificates support.
1 parent 7ec91eb commit f05ff4d

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

server.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const debug = require('debug')('bittorrent-tracker:server')
33
const dgram = require('dgram')
44
const EventEmitter = require('events')
55
const http = require('http')
6+
const https = require('https')
67
const peerid = require('bittorrent-peerid')
78
const series = require('run-series')
89
const string2compact = require('string2compact')
@@ -59,7 +60,12 @@ class Server extends EventEmitter {
5960

6061
// start an http tracker unless the user explictly says no
6162
if (opts.http !== false) {
62-
this.http = http.createServer()
63+
// Use (ot not) SSL Certificate
64+
if (typeof(opts.ssl)!="undefined"){
65+
this.http = https.createServer(opts.ssl)
66+
} else {
67+
this.http = http.createServer()
68+
}
6369
this.http.on('error', err => { this._onError(err) })
6470
this.http.on('listening', onListening)
6571

@@ -95,7 +101,12 @@ class Server extends EventEmitter {
95101
// start a websocket tracker (for WebTorrent) unless the user explicitly says no
96102
if (opts.ws !== false) {
97103
if (!this.http) {
98-
this.http = http.createServer()
104+
// Use (ot not) SSL Certificate
105+
if (typeof(opts.ssl)!="undefined"){
106+
this.http = https.createServer(opts.ssl)
107+
} else {
108+
this.http = http.createServer()
109+
}
99110
this.http.on('error', err => { this._onError(err) })
100111
this.http.on('listening', onListening)
101112

@@ -130,7 +141,12 @@ class Server extends EventEmitter {
130141

131142
if (opts.stats !== false) {
132143
if (!this.http) {
133-
this.http = http.createServer()
144+
// Use (ot not) SSL Certificate
145+
if (typeof(opts.ssl)!="undefined"){
146+
this.http = https.createServer(opts.ssl)
147+
} else {
148+
this.http = http.createServer()
149+
}
134150
this.http.on('error', err => { this._onError(err) })
135151
this.http.on('listening', onListening)
136152
}

0 commit comments

Comments
 (0)