Skip to content

Instantly share code, notes, and snippets.

@and1truong
Created August 19, 2015 11:22
Show Gist options
  • Save and1truong/e4fc259d337b8cf9a9a2 to your computer and use it in GitHub Desktop.
Save and1truong/e4fc259d337b8cf9a9a2 to your computer and use it in GitHub Desktop.
php -S localhost:8888 proxy-router.php
<?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