36 lines
874 B
PHP
36 lines
874 B
PHP
<?php
|
|
namespace Awaki;
|
|
|
|
use Index\StringBuilder;
|
|
use Index\Data\DbType;
|
|
use Index\Http\HttpFx;
|
|
|
|
require_once __DIR__ . '/../awaki.php';
|
|
|
|
$router = new HttpFx;
|
|
|
|
$router->use('/', function($response) {
|
|
$response->setPoweredBy('Awaki+Index');
|
|
});
|
|
|
|
$router->get('/', function() {
|
|
$body = '<!doctype html>';
|
|
$body .= '<title>Awaki</title>';
|
|
$body .= 'Redirect service - OK';
|
|
return $body;
|
|
});
|
|
|
|
$router->get('/:id', function($response, $request, $id) use ($db) {
|
|
$getInfo = $db->prepare('SELECT `redir_url` FROM `awk_redirects` WHERE `redir_id` = ? OR `redir_vanity` = ?');
|
|
$getInfo->addParameter(1, $id, DbType::INTEGER);
|
|
$getInfo->addParameter(2, $id, DbType::STRING);
|
|
$getInfo->execute();
|
|
$info = $getInfo->getResult();
|
|
|
|
if(!$info->next())
|
|
return 404;
|
|
|
|
$response->redirect($info->getString(0));
|
|
});
|
|
|
|
$router->dispatch();
|