Skip to content

Commit 86009a9

Browse files
committed
Added CrossOriginProxy class for cleaner Composer usage (if it works...)
1 parent bde8fa5 commit 86009a9

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Client-side HTTP requests, are limited by browser cross-origin restrictions.
55

66
Preferably fixed by [enabling CORS](http://enable-cors.org/server.html) on the server you're trying to call, but sometimes this just isn't possible because reasons.
77

8-
A simple workaround is having a proxy on the same domain as your client-side script and let it do these cross-domain requests server-side instead.
8+
A simple workaround is having a server-side proxy script on the same domain as your client-side script (e.g. both at `api.example.com`), and let the server do these cross-domain requests on behalf of the client.
99

10-
The script here, `proxy.php`, is such a script.
10+
This is such a script.
1111

1212

1313

@@ -29,13 +29,16 @@ the following dependency to your `composer.json`:
2929
},
3030
```
3131

32-
And then, for example, add a `proxy.php` like this:
32+
And then add a `proxy.php` like this to your web application:
3333

3434
``` PHP
3535
<?php
36-
37-
$whitelist = ['www.example.com', 'api.example.com'];
38-
require 'vendor/geekality/php-cross-domain-proxy/proxy.php';
36+
require 'vendor/autoload.php';
37+
38+
CrossOriginProxy::proxy([
39+
'www.example.com',
40+
'api.example.com',
41+
]);
3942

4043
```
4144

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"name": "geekality/php-cross-domain-proxy",
33
"description": "Simple PHP proxy for proxying cross-domain ajax requests.",
44
"keywords": ["php-cross-domain-proxy","cross-domain", "http", "proxy", "javascript", "ajax"],
5-
"license": "MIT",
65
"support": {
76
"issues": "https://github.com/Svish/php-cross-domain-proxy/issues",
87
"source": "https://github.com/Svish/php-cross-domain-proxy"
98
},
109
"require": {
1110
"php": ">=5.4.0",
1211
"lib-curl": ">=7.36"
12+
},
13+
"autoload": {
14+
"classmap": ["src/"]
1315
}
1416
}

src/CrossOriginProxy.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
class CrossOriginProxy
4+
{
5+
public static function proxy($whitelist = [], $timeout = 30, $maxredirs = 10)
6+
{
7+
require dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'proxy.php';
8+
}
9+
}

0 commit comments

Comments
 (0)