-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
57 lines (44 loc) · 1.55 KB
/
index.php
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
<?php
use Illuminate\Database\Capsule\Manager;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use ReactiveSlim\Server;
use ReactiveSlim\ServerEnvironment;
use Slim\App;
require 'vendor/autoload.php';
require 'config/settings.php';
require 'controllers/HomeController.php';
require 'middlewares/IPLogMiddleware.php';
$app = new App(['settings' => $config]);
$container = $app->getContainer();
$container['logger'] = function ($c) {
$loggerParam = $c['settings']['logger'];
$logger = new Logger($loggerParam['name']);
$file_handler = new StreamHandler($loggerParam['path']);
$logger->pushHandler($file_handler);
return $logger;
};
$container['localDb'] = function ($c) {
$db = $c['settings']['db'];
$pdo = new PDO('mysql:host=' . $db['host'] . ';dbname=' . $db['database'],
$db['username'], $db['password']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
};
$container['db'] = function ($container) {
$capsule = new Manager;
$capsule->addConnection($container['settings']['db']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
return $capsule;
};
$app->get('/', 'HomeController:home');
$app->add(new IPLogMiddleware($container->get('logger')));
$checkProxyHeaders = true;
$trustedProxies = ['10.0.0.1', '10.0.0.2'];
$app->add(new RKA\Middleware\IpAddress($checkProxyHeaders, $trustedProxies));
//$app->run();
(new Server($app))
->setEnvironment(ServerEnvironment::DEVELOPMENT)
->run();