1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <?php
use RingCentral\Psr7\Response;
function handler($request, $context): Response{ $path = $request->getAttribute('path');
if(!$path) { return error(); }
if(strpos($path, '/ajax/libs/') === 0) { return location('https://cdnjs.cloudflare.com/' . substr($path, strlen('/ajax/libs/'))); }
if(strpos($path, '/unpkg/') === 0) { return location('https://unpkg.com/' . substr($path, strlen('/unpkg/'))); }
if(strpos($path, '/php/') === 0) { return location('https://www.php.net/distributions/' . substr($path, strlen('/software/php/'))); }
if(strpos($path, '/node/') === 0) { return location('https://nodejs.org/dist/' . substr($path, strlen('/software/node/'))); }
if(strpos($path, '/python/') === 0) { return location('https://www.python.org/ftp/python/' . substr($path, strlen('/python/'))); }
return error(); }
function location(string $url): Response { return new Response(301, [ 'Location' => $url, ]); }
function error(): Response { return new Response(404, [ 'Content-Type'=> 'application/json' ]); }
|