Skip to content

Commit

Permalink
feat: allow whitelisting insecure HTTP servers for development purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
billiegoose committed Dec 14, 2018
1 parent 9b84000 commit 0c33823
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cors-proxy stop
Environment variables:
- `PORT` the port to listen to (if run with `npm start`)
- `ALLOW_ORIGIN` the value for the 'Access-Control-Allow-Origin' CORS header
- `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)

## License

Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const url = require('url')
const pkg = require('./package.json')
const {send} = require('micro')
const origin = process.env.ALLOW_ORIGIN
const insecure_origins = (process.env.INSECURE_HTTP_ORIGINS || '').split(',')
const allowHeaders = [
'accept-encoding',
'accept-language',
Expand Down Expand Up @@ -104,9 +105,10 @@ async function service (req, res) {
let parts = p.match(/\/([^\/]*)\/(.*)/)
let pathdomain = parts[1]
let remainingpath = parts[2]
console.log(`https://${pathdomain}/${remainingpath}`)
let protocol = insecure_origins.includes(pathdomain) ? 'http' : 'https'
console.log(`${protocol}://${pathdomain}/${remainingpath}`)
let f = await fetch(
`https://${pathdomain}/${remainingpath}`,
`${protocol}://${pathdomain}/${remainingpath}`,
{
method: req.method,
headers,
Expand Down

0 comments on commit 0c33823

Please sign in to comment.