-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
27 lines (22 loc) · 826 Bytes
/
index.mjs
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
import express from 'express';
import corsAnywhere from 'cors-anywhere';
import path from 'path';
const proxy = corsAnywhere.createServer({
originWhitelist: [], // Allow all origins
requireHeaders: [], // Do not require any headers.
removeHeaders: [] // Do not remove any headers.
});
const app = express();
const port = parseInt(process.env.PORT, 10) || 8080;
app.use('/public', express.static(path.resolve('public')));
app.get('/cors/:proxyUrl*', (req, res) => {
req.url = req.url.replace('/cors/', '/');
if (!req.url.includes('https://') && req.url.includes('https:/')) {
req.url = req.url.replace('https:/', 'https://');
}
proxy.emit('request', req, res);
});
app.get('*', (request, response) => {
response.sendFile(path.resolve('public', 'index.html'));
});
app.listen(port);