*/ $app->get('/(:site)', function () use($app) { $app->render('index.html'); }); /** * API CODE */ /** * Get-request to /api/ping/:url gets the location for a given url. * * @param {string} $url The url to get the location for. * @return {json} Returns the location-data in a json-object. */ $app->get('/api/ping/:url', function ($url) { $db = new Database(); $result = $db->getCachedURL($url); if (count($result) === 0) { // $out = file_get_contents('http://www.freegeoip.net/json/' . $url); $out = file_get_contents('http://ip-api.com/json/' . $url); $db->insertIPLocation($url, $out); $result = $db->getCachedURL($url); } echo json_encode($result); }); /** * Post-request to /api/traceroute/ performs a traceroute-command to the given url. * * The traceroute command output will be saved to a file. * * @return {int} Returns id of the traceroute request. */