flarum/api.php

43 lines
1020 B
PHP
Raw Normal View History

2015-06-17 00:00:20 +00:00
<?php
2015-08-26 07:43:18 +00:00
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Flarum\Api\Middleware\JsonApiErrors;
use Flarum\Core;
2015-08-26 07:43:18 +00:00
use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware;
2015-06-17 00:00:20 +00:00
use Zend\Diactoros\Server;
use Zend\Stratigility\MiddlewarePipe;
2015-08-12 07:47:13 +00:00
$app = require __DIR__.'/flarum/bootstrap.php';
2015-06-17 00:00:20 +00:00
$app->register('Flarum\Api\ApiServiceProvider');
$api = new MiddlewarePipe();
$api->pipe($app->make('Flarum\Api\Middleware\ReadJsonParameters'));
$api->pipe($app->make('Flarum\Api\Middleware\LoginWithHeader'));
2015-08-26 22:48:54 +00:00
$apiPath = parse_url(Core::url('api'), PHP_URL_PATH);
2015-08-26 07:43:18 +00:00
$router = $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.api.routes')]);
$api->pipe($apiPath, $router);
2015-09-14 06:49:20 +00:00
$api->pipe(new JsonApiErrors());
2015-06-17 00:00:20 +00:00
$server = Server::createServer(
2015-08-26 07:43:18 +00:00
$api,
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
2015-06-17 00:00:20 +00:00
);
$server->listen();