Skip to content
Snippets Groups Projects
Select Git revision
  • 9b6bd7e747bd5ed44d169a8e1baee0e519d209d6
  • main default protected
  • 5.5 protected
  • atlantis
  • 5.3 protected
  • 5.0 protected
  • issue-23
  • issue8-seat-logging-and-export
  • ticket-216
  • tickets-215-216-241-242
10 results

middleware.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    middleware.php 1.40 KiB
    <?php
    namespace JsonApi;
    
    use Slim\App;
    
    return function (App $app) {
        /** @var \DI\Container */
        $container = $app->getContainer();
    
        $app->addBodyParsingMiddleware([
            'application/vnd.api+json' => function ($input) {
                return json_decode($input, true);
            },
        ]);
    
        // set 'request' in container
        $app->add(function ($request, $handler) use ($container) {
            $container->set('request', $request);
    
            return $handler->handle($request);
        });
    
        $app->add(new Middlewares\StudipMockNavigation());
        $app->add(new Middlewares\RemoveTrailingSlashes());
    
        // Add Routing Middleware
        $app->addRoutingMiddleware();
    
        /** @var array|null */
        $corsOrigin = \Config::get()->getValue('JSONAPI_CORS_ORIGIN');
        if (is_array($corsOrigin) && count($corsOrigin)) {
            $app->add(
                new \Tuupola\Middleware\CorsMiddleware([
                    'origin' => $corsOrigin,
                    'methods' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
                    'headers.allow' => [
                        'Accept',
                        'Accept-Encoding',
                        'Accept-Language',
                        'Authorization',
                        'Content-Type',
                        'Origin',
                    ],
                    'headers.expose' => ['Etag'],
                    'credentials' => true,
                    'cache' => 86400,
                ])
            );
        }
    };