forked from uNetworking/uWebSockets.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerName.js
34 lines (28 loc) · 1.01 KB
/
ServerName.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
/* Minimal SSL example using ServerNameIndication */
const uWS = require('../dist/uws.js');
const port = 9001;
const app = uWS.SSLApp({
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).missingServerName((hostname) => {
/* Note: You don't have to use this callback but can pre-load
* relevant server names up front. This callback is not "async",
* you either add the server name HERE IMMEDIATELY, or the hangshake
* will continue with default certificate (which will most likely fail) */
console.log("Hello! We are missing server name <" + hostname + ">");
/* We simply assume it is localhost, so adding it here */
app.addServerName("localhost", {
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
});
}).get('/*', (res, req) => {
res.end('Hello World!');
}).listen(port, (token) => {
if (token) {
console.log('Listening to port ' + port);
} else {
console.log('Failed to listen to port ' + port);
}
});