Something went wrong. Try again.
A barebones implementation of an atproto PDS in PHP and Slim Framework 4.
pds php atproto
Something went wrong. Try again.
1.7 kB · 53 lines
PHP
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354<?php
declare(strict_types=1);
namespace App\Application\ResponseEmitter;
use Psr\Http\Message\ResponseInterface;use Slim\ResponseEmitter as SlimResponseEmitter;
class ResponseEmitter extends SlimResponseEmitter{ /** * {@inheritdoc} */ public function emit(ResponseInterface $response): void { // This variable should be set to the allowed host from which your API can be accessed with $origin = is_string($_SERVER['HTTP_ORIGIN'] ?? null) ? $_SERVER['HTTP_ORIGIN'] : '';
$allowedHeaders = implode(', ', [ 'X-Requested-With', 'Content-Type', 'Accept', 'Origin', 'Authorization', 'DNT', 'Keep-Alive', 'User-Agent', 'If-Modified-Since', 'Cache-Control', 'Range', 'DPoP', 'atproto-accept-labelers', 'atproto-proxy', ]);
$response = $response ->withHeader('Access-Control-Allow-Credentials', 'true') ->withHeader('Access-Control-Allow-Origin', $origin) ->withHeader('Access-Control-Allow-Headers', $allowedHeaders) ->withHeader('Access-Control-Expose-Headers', 'DPoP-Nonce') ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS') ->withHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') ->withAddedHeader('Cache-Control', 'post-check=0, pre-check=0') ->withHeader('Pragma', 'no-cache');
if (ob_get_contents()) { ob_clean(); }
parent::emit($response); }}