Fixed some templates not rendering.

This commit is contained in:
flash 2024-08-04 23:24:09 +00:00
parent 42d6c2d072
commit 4c74208e2b
3 changed files with 21 additions and 2 deletions

View file

@ -9,6 +9,7 @@ class RoutingContext {
public function __construct(SeriaContext $context) {
$this->router = new HttpRouter(errorHandler: new RoutingErrorHandler($context));
$this->router->use('/', fn($resp) => $resp->setPoweredBy('Seria'));
$this->router->registerContentHandler(new StringableContentHandler); // this should really be in Index lol but i can't be bothered rn!
}
public function getRouter(): IRouter {

View file

@ -0,0 +1,18 @@
<?php
namespace Seria;
use Stringable;
use Index\Http\HttpResponseBuilder;
use Index\Http\Content\StringContent;
use Index\Http\ContentHandling\IContentHandler;
class StringableContentHandler implements IContentHandler {
public function match(mixed $content): bool {
return $content instanceof Stringable;
}
/** @param Stringable $content */
public function handle(HttpResponseBuilder $response, mixed $content): void {
$response->setContent(new StringContent((string)$content));
}
}

View file

@ -17,8 +17,8 @@ class AnnounceRouting extends RouteHandler {
#[HttpGet('/announce')]
#[HttpGet('/announce.php')]
#[HttpGet('/announce/:key')]
#[HttpGet('/announce.php/:key')]
#[HttpGet('/announce/([A-Za-z0-9]+)')]
#[HttpGet('/announce.php/([A-Za-z0-9]+)')]
public function getAnnounce($response, $request, string $key = '') {
if(strlen(inet_pton($_SERVER['REMOTE_ADDR'])) !== 4)
return new AnnounceFailure('Tracker is only supported over IPv4, please reset your DNS cache.');