updated cors-proxy to use given env variables
This commit is contained in:
39
index.mjs
Normal file
39
index.mjs
Normal file
@@ -0,0 +1,39 @@
|
||||
import cors_proxy from 'cors-anywhere'
|
||||
import {env} from 'process'
|
||||
|
||||
let HOST = env.HOST || 'localhost'
|
||||
let PORT = env.PORT || 1337
|
||||
let USER = env.USER || ''
|
||||
let PW = env.PW || ''
|
||||
|
||||
const token = USER !== "" && PW !== ""
|
||||
? btoa(unescape(encodeURIComponent(USER + ':' + PW)))
|
||||
: ""
|
||||
|
||||
const headers = {}
|
||||
if (token !== "")
|
||||
headers.Authorization = `Basic ${token}`
|
||||
|
||||
cors_proxy
|
||||
.createServer({
|
||||
originWhitelist: [], // allow all origins
|
||||
requireHeader: ['origin', 'x-requested-with'],
|
||||
setHeaders: headers,
|
||||
removeHeaders: [
|
||||
'cookie',
|
||||
'cookie2',
|
||||
'x-request-start',
|
||||
'x-request-id',
|
||||
'via',
|
||||
'connect-time',
|
||||
'total-route-time',
|
||||
],
|
||||
redirectSameOrigin: true,
|
||||
httpProxyOptions: {
|
||||
// Do not add X-Forwarded-For, etc. headers, because Heroku already adds it.
|
||||
xfwd: false,
|
||||
},
|
||||
})
|
||||
.listen(PORT, HOST, () => {
|
||||
console.log(`Running CORS Anywhere on 'http://${HOST}:${PORT}/'`)
|
||||
})
|
Reference in New Issue
Block a user