Fixed some templates not rendering.
This commit is contained in:
parent
42d6c2d072
commit
4c74208e2b
3 changed files with 21 additions and 2 deletions
|
@ -9,6 +9,7 @@ class RoutingContext {
|
||||||
public function __construct(SeriaContext $context) {
|
public function __construct(SeriaContext $context) {
|
||||||
$this->router = new HttpRouter(errorHandler: new RoutingErrorHandler($context));
|
$this->router = new HttpRouter(errorHandler: new RoutingErrorHandler($context));
|
||||||
$this->router->use('/', fn($resp) => $resp->setPoweredBy('Seria'));
|
$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 {
|
public function getRouter(): IRouter {
|
||||||
|
|
18
src/StringableContentHandler.php
Normal file
18
src/StringableContentHandler.php
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,8 +17,8 @@ class AnnounceRouting extends RouteHandler {
|
||||||
|
|
||||||
#[HttpGet('/announce')]
|
#[HttpGet('/announce')]
|
||||||
#[HttpGet('/announce.php')]
|
#[HttpGet('/announce.php')]
|
||||||
#[HttpGet('/announce/:key')]
|
#[HttpGet('/announce/([A-Za-z0-9]+)')]
|
||||||
#[HttpGet('/announce.php/:key')]
|
#[HttpGet('/announce.php/([A-Za-z0-9]+)')]
|
||||||
public function getAnnounce($response, $request, string $key = '') {
|
public function getAnnounce($response, $request, string $key = '') {
|
||||||
if(strlen(inet_pton($_SERVER['REMOTE_ADDR'])) !== 4)
|
if(strlen(inet_pton($_SERVER['REMOTE_ADDR'])) !== 4)
|
||||||
return new AnnounceFailure('Tracker is only supported over IPv4, please reset your DNS cache.');
|
return new AnnounceFailure('Tracker is only supported over IPv4, please reset your DNS cache.');
|
||||||
|
|
Loading…
Reference in a new issue