-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathredirect.js
More file actions
78 lines (61 loc) · 2.36 KB
/
Copy pathredirect.js
File metadata and controls
78 lines (61 loc) · 2.36 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot certonly --standalone
www.bluepyrami.de
193.197.228.28
2001:7c0:2330:137:f816:3eff:fe01:9c40
Certificate is saved at: /etc/letsencrypt/live/www.bluepyrami.de/fullchain.pem
Key is saved at: /etc/letsencrypt/live/www.bluepyrami.de/privkey.pem
https://www.bluepyrami.de:8443/
http://www.bluepyrami.de:8080/
*/
/////////////////////////////////////////////////////////////////////////////80
// General Purpose STATIC Web Server
// andreas.roessler@hs-esslingen.de
// 08.02.2018
const http = require( 'http' );
const https = require( 'https' );
const fs = require( 'fs' );
const path = require( 'path' );
const secureport = process.env.SPORT || 8443;
const standardport = process.env.PORT || 8080;
const API_SERVICE_URL = "https://jsonplaceholder.typicode.com";
/////////////////////////////////////////////////////////////////////////////80
const certdir = "/etc/letsencrypt/live/www.bluepyrami.de";
const credentials = {
key: fs.readFileSync( path.join( certdir, 'privkey.pem' ), "utf8" ),
cert: fs.readFileSync( path.join( certdir, 'fullchain.pem' ) , "utf8" ),
};
/////////////////////////////////////////////////////////////////////////////80
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
app.use("/info", (req, res) => {
res.send('Hello Info!');
});
app.use('/json_placeholder', createProxyMiddleware({
target: API_SERVICE_URL,
changeOrigin: true,
pathRewrite: {
[`^/json_placeholder`]: '',
},
}));
app.use((req, res) => {
res.send('Hello All!');
});
/////////////////////////////////////////////////////////////////////////////80
https.createServer( credentials, app ).listen( secureport, function() {
console.log( '%s Node HTTPS server started on port %d ...', Date( Date.now() ), secureport );
} );
/////////////////////////////////////////////////////////////////////////////80
// Redirect from http standardport 8080 to https
http.createServer( function( req, res ) {
const host = req.headers[ 'host' ].replace( '' + port, '' + secureport );
res.writeHead( 301, {
"Location": "https://" + host + req.url
} );
res.end();
} ).listen( standardport, function() {
console.log( '%s Node HTTP redirect started on port %d ...', Date( Date.now() ), standardport );
} );