awaki/public/index.php

42 lines
1,008 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;
$targetUrl = $info->getString(0);
$params = $request->getParamString();
if(!empty($params))
$targetUrl .= '?' . $params;
$response->redirect($targetUrl);
});
$router->dispatch();