-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.php
More file actions
64 lines (53 loc) · 2.14 KB
/
index.php
File metadata and controls
64 lines (53 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
// set up some constants first, because some of my friends are probably going
// to be setting this up in a manner that is "security conscious" - moving the
// app directory outside of this folder and into its parent somewhere
define('PHAR_MODE', class_exists('Phar') && Phar::running());
if (!defined('APP_DIR')) {
if (PHAR_MODE) {
define('APP_DIR', realpath(getcwd() . '/app'));
define('APP_VENDOR_DIR', 'phar://' . basename(__DIR__) . '/app/vendor');
} else {
define('APP_DIR', realpath(__DIR__ . '/app'));
define('APP_VENDOR_DIR', realpath(APP_DIR . '/vendor'));
}
}
// require composer
require APP_VENDOR_DIR . '/autoload.php';
use League\Container\Container;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Exception\HttpNotFoundException;
use Slim\Factory\AppFactory;
// set up service provider
$container = new Container();
$container->addServiceProvider(App\ServiceProvider::class);
// start messing about with slim
$app = AppFactory::createFromContainer($container);
$app->any('/dl', function (Request $request, Response $response, array $arguments) {
$response->getBody()->write('85');
return $response;
});
$app->any('/', function (Request $request, Response $response, array $arguments) {
return $response->withStatus(200);
});
$app->group('/api', App\Router\Api::class);
$app->group('/page', App\Router\Page::class);
$app->any('/{alias:[\w\.]*?}', new App\Router\FileRoute($app));
$app->any('/{alias:[\w\.]*?}/{ext}', new App\Router\FormattedFileRoute($app));
$afterMiddleware = function ($request, $handler) {
try {
$response = $handler->handle($request);
} catch (UnexpectedValueException $exception) {
return (new Slim\Psr7\Response())->withStatus(404);
} catch (HttpNotFoundException $exception) {
return (new Slim\Psr7\Response())->withStatus(404);
} catch (Throwable $exception) {
$response = new Slim\Psr7\Response();
$response->getBody()->write('-1');
return $response->withStatus(500);
}
return $response;
};
$app->add($afterMiddleware);
$app->run();