-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproxy.js
62 lines (47 loc) · 1.67 KB
/
proxy.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
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
const Bundler = require('parcel-bundler');
const express = require('express');
const fs = require('fs');
const https = require('https');
const http = require('http');
const {createProxyMiddleware: proxy} = require('http-proxy-middleware');
const app = express();
const apitoken = process.env.listennotes;
app.use('/api', proxy({
pathRewrite: {'/api' : '/.netlify/functions/'},
target: 'http://localhost:9000',
changeOrigin: true,
}));
app.use('/rss-full', proxy({
pathRewrite: {'/rss-full' : '/.netlify/functions/findCast/'},
target: 'http://localhost:9000',
changeOrigin: true,
}));
app.use('/rss-audio', proxy({
pathRewrite: {'/rss-audio' : '/rss-audio'},
target: 'http://phonograph.app',
changeOrigin: true,
}));
app.use('/ln', proxy({
pathRewrite: {'/ln' : '/api/v2/'},
target: 'https://listen-api.listennotes.com',
changeOrigin: true,
onProxyReq(proxyReq, req, res){
proxyReq.setHeader('X-ListenAPI-Key',apitoken);
proxyReq.setHeader('X-From', 'Gramophone-DEV');
proxyReq.end();
}
}));
const bundler = new Bundler('public/index.html');
app.use(bundler.middleware());
// app.listen(Number(process.env.PORT || 1234));
const cert = "/etc/letsencrypt/live/cloud.hosts.mx/fullchain.pem";
const key = "/etc/letsencrypt/live/cloud.hosts.mx/privkey.pem";
const privateKey = fs.readFileSync(key);
const certificate = fs.readFileSync(cert);
const credentials = {key: privateKey, cert: certificate};
https.createServer(credentials, app)
.listen(1234, () => console.log("Running!"));
http.createServer(function (req, res) {
res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
res.end();
}).listen(4234);