-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathhttps_server.js
More file actions
40 lines (32 loc) · 1007 Bytes
/
https_server.js
File metadata and controls
40 lines (32 loc) · 1007 Bytes
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
/*
* https server
* Kyuho Kim (ekyuho@gmail.com)
*
* Create Self-Signed Certificate https://geekflare.com/openssl-commands-certificates/
* openssl req -x509 -sha256 -nodes -newkey rsa:2048 -keyout gfselfsigned.key -out gfcert.pem
*
*/
var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');
var options = {
cert: fs.readFileSync("gfcert.pem"),
key: fs.readFileSync("gfselfsigned.key")
};
app = express()
apps = express()
app.get('/', function(req,res) {
console.log("http got %j", req.query)
res.send('hello http '+ JSON.stringify(req.query));
});
apps.get('/', function(req,res) {
console.log("https got %j", req.query)
res.send('hello https '+ JSON.stringify(req.query));
});
http.createServer(app).listen(8000, function(){
console.log("http server http://IP_ADDRESS:8000/")
});
https.createServer(options, apps).listen(8001, function(){
console.log("secure server https://IP_ADDRESS:8001/")
});