forked from koding/koding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·50 lines (46 loc) · 1.47 KB
/
Copy pathserver.js
File metadata and controls
executable file
·50 lines (46 loc) · 1.47 KB
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 https = require('https');
var fs = require('fs');
var dnode = require('dnode');
try {
var opts = {
key : fs.readFileSync(__dirname + '/privatekey.pem'),
cert : fs.readFileSync(__dirname + '/certificate.pem'),
};
}
catch (e) {
console.log('# {privatekey,certificate}.pem missing, do this first:');
console.log('openssl genrsa -out privatekey.pem 1024');
console.log('openssl req -new -key privatekey.pem -out certrequest.csr');
console.log('openssl x509 -req -in certrequest.csr '
+ '-signkey privatekey.pem -out certificate.pem');
process.exit();
}
var index = fs.readFileSync(__dirname + '/index.html');
var server = https.createServer(opts, function (req, res) {
if (req.url === '/') {
res.writeHead(200, { 'Content-Type' : 'text/html' });
res.end(index);
}
else if (!res.finished) {
process.nextTick(function () {
if (!res.finished) {
res.writeHead(404, { 'Content-Type' : 'text/html' });
res.end('Not found!');
}
});
}
});
dnode(function (client) {
this.timesTen = function (n,f) { f(n * 10) };
this.whoAmI = function (reply) {
client.name(function (name) {
reply(name
.replace(/Mr\.?/,'Mister')
.replace(/Ms\.?/,'Miss')
.replace(/Mrs\.?/,'Misses')
);
})
};
}).listen(server);
server.listen(8020);
console.log('https://localhost:8020/');