Created
August 19, 2015 11:22
-
-
Save and1truong/e4fc259d337b8cf9a9a2 to your computer and use it in GitHub Desktop.
php -S localhost:8888 proxy-router.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('BASE_URL', 'http://example.com'); | |
if ('cli-server' === php_sapi_name()) { | |
$file = preg_replace('/\?.+/', '', __DIR__ . $_SERVER['REQUEST_URI']); | |
if (!is_file($file)) { | |
$url = str_replace(__DIR__, $base_url, $file); | |
$path = trim(parse_url($url)['path'], '/'); | |
$dir = dirname($path); | |
exec(implode('; ', [ | |
"mkdir -p '$dir'", | |
"wget '$url' -O '$path'" | |
])); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment