-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
21 lines (20 loc) · 732 Bytes
/
server.js
File metadata and controls
21 lines (20 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//http
//listen on default port 80
const http = require('http');
http.createServer((req, res) => {
console.log(`${req.method} ${req.headers.host}:${req.client.localPort}${req.url}`)
res.end('Got HTTP\n');
}).listen(80, ()=>console.log('http://localhost:80'));
//https
//get credentials from file (run makeKeys.sh to generate keys)
const fs = require('fs');
const options = {
key: fs.readFileSync('./key.pem'),
cert: fs.readFileSync('./cert.pem')
};
//listen on default port 443
const https = require('https');
https.createServer(options, (req, res) => {
console.log(`${req.method} ${req.headers.host}:${req.client.localPort}${req.url}`)
res.end('Got HTTPS\n');
}).listen(443, ()=>console.log('https://localhost:443'));