Skip to content

Commit 0c33823

Browse files
committed
feat: allow whitelisting insecure HTTP servers for development purposes
1 parent 9b84000 commit 0c33823

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ cors-proxy stop
4444
Environment variables:
4545
- `PORT` the port to listen to (if run with `npm start`)
4646
- `ALLOW_ORIGIN` the value for the 'Access-Control-Allow-Origin' CORS header
47+
- `INSECURE_HTTP_ORIGINS` comma separated list of origins for which HTTP should be used instead of HTTPS (added to make developing against locally running git servers easier)
4748

4849
## License
4950

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const url = require('url')
33
const pkg = require('./package.json')
44
const {send} = require('micro')
55
const origin = process.env.ALLOW_ORIGIN
6+
const insecure_origins = (process.env.INSECURE_HTTP_ORIGINS || '').split(',')
67
const allowHeaders = [
78
'accept-encoding',
89
'accept-language',
@@ -104,9 +105,10 @@ async function service (req, res) {
104105
let parts = p.match(/\/([^\/]*)\/(.*)/)
105106
let pathdomain = parts[1]
106107
let remainingpath = parts[2]
107-
console.log(`https://${pathdomain}/${remainingpath}`)
108+
let protocol = insecure_origins.includes(pathdomain) ? 'http' : 'https'
109+
console.log(`${protocol}://${pathdomain}/${remainingpath}`)
108110
let f = await fetch(
109-
`https://${pathdomain}/${remainingpath}`,
111+
`${protocol}://${pathdomain}/${remainingpath}`,
110112
{
111113
method: req.method,
112114
headers,

0 commit comments

Comments
 (0)