Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates from upstream #5

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
755b339
modified custom target example
cesine Feb 5, 2013
4d521dc
Merge pull request #8 from iLanguage/master
gr2m Feb 5, 2013
2910104
version bump
gr2m Feb 5, 2013
5a72d74
fixed port
gr2m Feb 13, 2013
d861d95
versiom bump
gr2m Feb 13, 2013
afad88e
listen to port 80 if no port is specified
janl Jan 29, 2013
1cf0616
error gracefully on raw browser access. closes #10
janl Feb 17, 2013
9294b07
add MIT license
janl Mar 25, 2013
1a9131e
Remove log statement
daleharvey Apr 30, 2013
f128d7d
Merge pull request #12 from daleharvey/remove-spurious-output
gr2m May 2, 2013
bd881c4
version bump
gr2m May 3, 2013
d1772ad
Default to target port 80 if unspecified
ksheedlo Jun 6, 2013
a789d16
Merge pull request #13 from ksheedlo/master
gr2m Jun 7, 2013
53ee033
removed console.log
gr2m Jun 7, 2013
a04826f
bump version
janl Jul 25, 2013
1e5def8
Add basic auth headers when they passed in
daleharvey Jul 29, 2013
ecff34a
Merge pull request #16 from daleharvey/add-auth
janl Jul 29, 2013
1d86e7a
Add auth header when specifying credentials via target url param
daleharvey Sep 21, 2013
60df5bb
Merge pull request #19 from daleharvey/add-auth-properly
janl Sep 21, 2013
31bea3f
bump version
janl Sep 22, 2013
7b2c276
Update http-proxy version
gingermusketeer Dec 12, 2013
e2d93c4
Merge pull request #22 from mediasuitenz/master
janl Dec 12, 2013
fe94061
chore(release): 1.0.0
gr2m Apr 28, 2015
d4740f4
fix: allow to set port number via `proces.env.PORT`
gr2m Apr 28, 2015
908f3ce
chore(package): added license MIT, updated description
gr2m Apr 28, 2015
d1acc55
docs(README): now standalone only
gr2m Apr 28, 2015
a8833eb
chore: removed obsolete CAKEFILE
gr2m May 22, 2015
f24bfba
chore: deleted LICENSE file. It's still MIT as stated in README
gr2m May 22, 2015
2fd5519
Header name fixed: 'access-control-request-headers'
denis-pakizh May 20, 2015
33bcb53
docs(README): default port is now 1337
gr2m May 22, 2015
4f26855
'Host' request header fixed
denispakizh May 25, 2015
76ed1fd
Merge pull request #36 from denispakizh/host-hdr-fix
janl May 25, 2015
d3f8102
To forward query string parameters
denis-pakizh Jun 10, 2015
ea82621
Merge pull request #37 from denispakizh/url-query-params
janl Jun 16, 2015
08af6cd
1.1.0
gr2m Jun 17, 2015
b40e6cd
docs: add usage to public index.html page
gr2m Aug 17, 2015
41c1eb8
chore(package): semantic-release setup
gr2m Aug 17, 2015
7193c00
chore(travis): initial version
gr2m Aug 17, 2015
f4871a8
fix: add empty favicon to avoid errors when loading default page
gr2m Aug 17, 2015
2a7f060
chore(package): updated to hapi@9. Adds vision for test server
gr2m Aug 17, 2015
2faa057
feat: start test server with `DEBUG=1 npm start`
gr2m Aug 17, 2015
263dfd6
docs(README): start test server with `DEBUG=1 npm start`
gr2m Aug 17, 2015
44af59d
chore(package): updated dependencies
gr2m Aug 17, 2015
ddec21e
docs(README): badges
gr2m Aug 17, 2015
936f217
chore(package): add dependencies for CI tests
gr2m Aug 17, 2015
b5775e0
chore(travis): run test in Firefox on Travis
gr2m Aug 17, 2015
82f5939
test: initial version
gr2m Aug 17, 2015
0e97c64
fix(package): adds missing devDependency: request
gr2m Aug 17, 2015
ecd99c1
test: check for request results
gr2m Aug 17, 2015
6314b03
chore(package): hapi-cors-headers
gr2m Aug 17, 2015
180aa0c
feat: use hapi-cors-headers instead of own implementation
gr2m Aug 17, 2015
955a866
fix(package): adds missing dependency: ejs
gr2m Aug 17, 2015
697e7c2
chore(travis): test in node@4
gr2m Oct 28, 2015
bbe3c50
docs(README): add `CORSPROXY_HOST` env option
gr2m Oct 28, 2015
d3d5340
feat: set custom host using `CORSPROXY_HOST` env variable
gr2m Oct 28, 2015
81dcc27
feat: CORSPROXY_MAX_PAYLOAD option (#47)
rocwind Sep 26, 2016
62c6d9b
chore: activate probot-stale
gr2m May 10, 2017
c29a603
Add instructions to run with different hostname
rmetcalf9 Jul 12, 2017
8809410
Add docker alternative
FuriKuri Oct 5, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# see available options / defaults at https://github.com/probot/stale/#usage
daysUntilStale: 60
daysUntilClose: 7
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
notifications:
email: false
node_js:
- '6'
before_install:
- npm i -g npm@^3.0.0
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
script: TEST_CLIENT=selenium:firefox npm test
before_script:
- npm prune
after_success:
- npm run semantic-release
9 changes: 0 additions & 9 deletions CAKEFILE

This file was deleted.

9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:8

RUN npm install -g corsproxy

EXPOSE 1337

ENV CORSPROXY_HOST 0.0.0.0

ENTRYPOINT ["corsproxy"]
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

65 changes: 32 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
## Installation
# corsproxy

As a standalone tool:
> standalone CORS proxy

$ npm install -g corsproxy
[![Build Status](https://travis-ci.org/gr2m/CORS-Proxy.svg?branch=master)](https://travis-ci.org/gr2m/CORS-Proxy)
[![Dependency Status](https://david-dm.org/gr2m/CORS-Proxy.svg)](https://david-dm.org/gr2m/CORS-Proxy)
[![devDependency Status](https://david-dm.org/gr2m/CORS-Proxy/dev-status.svg)](https://david-dm.org/gr2m/CORS-Proxy#info=devDependencies)

As a dependency:
[![NPM](https://nodei.co/npm/corsproxy.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/corsproxy/)

$ npm install corsproxy

## Setup

## Running
```
npm install -g corsproxy
corsproxy
# with custom port: CORSPROXY_PORT=1234 corsproxy
# with custom host: CORSPROXY_HOST=localhost corsproxy
# with debug server: DEBUG=1 corsproxy
# with custom payload max bytes set to 10MB (1MB by default): CORSPROXY_MAX_PAYLOAD=10485760 corsproxy
```

Standalone:
### Docker

$ corsproxy
CORS Proxy started on localhost:9292
It is also possible to run the cors proxy in a docker container:

Standalone with custom host/port:
```
# Build image
docker build -t corsproxy .

$ corsproxy 0.0.0.0 1234
CORS Proxy started on 0.0.0.0:1234
# Run container
docker run -p 1337:1337 --name corsproxy -d corsproxy
```

As a dependency:

var cors_proxy = require("corsproxy");
var http_proxy = require("http-proxy");
http_proxy.createServer(cors_proxy).listen(1234);

With custom target:
## Usage

var cors_proxy = require("corsproxy");
var http_proxy = require("http-proxy");
cors_proxy.options = {
target: {
host:"0.0.0.0",
port:5984
}
};
http_proxy.createServer(cors_proxy).listen(1234);
The cors proxy will start at http://localhost:1337.
To access another domain, use the domain name (including port) as the first folder, e.g.

- http://localhost:1337/localhost:3000/sign_in
- http://localhost:1337/my.domain.com/path/to/resource
- etc etc

## Usage
By default the cors proxy will only answer requests sent to localhost. To use another domain (e.g. machine name) set an enviroment variable CORSPROXY_HOST to the required value before launching.

The cors proxy will start at http://localhost:9292. To access another domain, use the domain name (including port) as the first folder, e.g.
## License

http://localhost:9292/localhost:3000/sign_in
http://localhost:9292/my.domain.com/path/to/resource
etc etc
MIT
120 changes: 120 additions & 0 deletions bin/corsproxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/env node

var Hapi = require('hapi')
var plugin = require('../index')
var good = require('good')
var loggerOptions = require('../lib/logger-options')

var server = new Hapi.Server({})
var port = parseInt(process.env.CORSPROXY_PORT || process.env.PORT || 1337, 10)
var host = (process.env.CORSPROXY_HOST || 'localhost');
var maxPayload = parseInt(process.env.CORSPROXY_MAX_PAYLOAD || 1048576, 10)
var proxy = server.connection({ port: port, labels: ['proxy'], host: host})

server.register(require('inert'), function () {})
server.register(require('h2o2'), function () {})

// cors plugin
server.register(plugin, {
select: ['proxy']
}, function (error) {
if (error) server.log('error', error)
})

// logger plugin
server.register({
register: good,
options: loggerOptions
}, function (error) {
if (error) server.log('error', error)
})

// proxy route
proxy.route({
method: '*',
path: '/{host}/{path*}',
handler: {
proxy: {
passThrough: true,
mapUri: function (request, callback) {
request.host = request.params.host
request.path = request.path.substr(request.params.host.length + 1)
request.headers['host'] = request.host
var query = request.url.search ? request.url.search : ''
console.log('proxy to http://' + request.host + request.path)
callback(null, 'http://' + request.host + request.path + query, request.headers)
}
}
},
config: {
payload: {
maxBytes: maxPayload
}
}
})

// default route
proxy.route({
method: 'GET',
path: '/',
handler: {
file: 'public/index.html'
}
})
proxy.route({
method: 'GET',
path: '/favicon.ico',
handler: {
file: 'public/favicon.ico'
}
})

if (process.env.DEBUG) {
var testport = port + 1
var test = server.connection({ port: testport, labels: ['test'], host: host })

server.register(require('vision'), function (error) {
if (error) {
throw error
}

server.views({
engines: { ejs: require('ejs') },
path: 'public/test'
})
})

test.route({
method: 'GET',
path: '/favicon.ico',
handler: {
file: 'public/favicon.ico'
}
})
test.route({
method: 'GET',
path: '/test.json',
handler: {
file: 'public/test/test.json'
}
})

test.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply.view('index', {
proxyPort: proxy.info.port,
testPort: test.info.port
})
}
})

server.log('info', 'Debug server starting at: ' + test.info.uri)
}

server.start(function (error) {
if (error) server.log('error', error)

server.log('info', 'CORS Proxy running at: ' + proxy.info.uri)
})
10 changes: 0 additions & 10 deletions bin/index.js

This file was deleted.

48 changes: 48 additions & 0 deletions bin/test-background
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

set -e

function cleanup {
set +e

npm run kill_selenium

echo "\nYou can safely ignore errors below, if you see any"

# kill chrome driver
CHROMEDRIVER_PID=`ps -ef | grep chromedriver | grep -v grep | awk '{print $2}'`
if [ "$CHROMEDRIVER_PID" ] ; then
kill -9 $CHROMEDRIVER_PID
fi
# kill test app
APP_PID=`ps -ef | grep 'corsproxy' | grep -v grep | awk '{print $2}'`
if [ "$APP_PID" ] ; then
kill -9 $APP_PID
fi
}

# always kill selenium, no matter if tests pass or exit
trap cleanup EXIT

if [ ! -d "/tmp/sv-selenium" ]; then
echo 'Selenium not yet installed, downloading & installing ...'
npm run install_selenium_and_chromedriver
fi

npm run start_selenium_with_chromedriver &
DEBUG=1 npm start &

COUNTER=0
until $(curl --output /dev/null --silent --head --fail http://localhost:1338); do
let COUNTER=COUNTER+1
echo "Waiting for app ... $COUNTER / 60"
sleep 1
if [[ COUNTER -eq 60 ]] ; then
echo ""
echo "App start timeout"
exit 1
fi
done
echo 'App started :)'

npm run test:mocha
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var addCorsHeaders = require('hapi-cors-headers')
var pkg = require('./package.json')

function corsPlugin (server, options, next) {
server.ext('onPreResponse', addCorsHeaders)
next()
}

corsPlugin.attributes = {
pkg: pkg
}
module.exports = corsPlugin
66 changes: 0 additions & 66 deletions lib/corsproxy.js

This file was deleted.

Loading