227 lines
6.6 KiB
PHP
Raw Normal View History

2018-04-21 12:59:48 +05:00
<?php
2019-05-12 18:42:53 +05:00
use PackageVersions\Versions;
2018-04-21 12:59:48 +05:00
require_once __DIR__.'/../vendor/autoload.php';
2019-07-17 04:55:30 +05:00
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
))->bootstrap();
2018-04-21 12:59:48 +05:00
/*
Defines
*/
2019-05-13 08:19:23 +05:00
defined('BLACKLIST_PATH') or define('BLACKLIST_PATH', __DIR__.'/../storage/app/blacklist.json');
defined('JIKAN_PARSER_VERSION') or define('JIKAN_PARSER_VERSION', Versions::getVersion('jikan-me/jikan'));
2018-04-21 12:59:48 +05:00
2019-11-15 10:52:05 -08:00
2018-04-21 12:59:48 +05:00
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);
2020-05-21 08:28:18 +05:00
$app->register(Jenssegers\Mongodb\MongodbServiceProvider::class);
2018-08-16 02:29:25 +05:00
$app->withFacades();
$app->withEloquent();
2018-04-21 12:59:48 +05:00
/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
2018-08-12 02:45:26 +05:00
2018-04-21 12:59:48 +05:00
/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/
2018-08-16 02:29:25 +05:00
$app->routeMiddleware([
2020-06-08 02:35:30 +05:00
// 'blacklist' => App\Http\Middleware\Blacklist::class,
// 'slave-auth' => App\Http\Middleware\SlaveAuthentication::class,
// 'meta' => App\Http\Middleware\Meta::class,
// 'cache-resolver' => App\Http\Middleware\CacheResolver::class,
// 'throttle' => App\Http\Middleware\Throttle::class,
// 'etag' => \App\Http\Middleware\EtagMiddleware::class,
// 'microcaching' => \App\Http\Middleware\MicroCaching::class,
'database-resolver' => \App\Http\Middleware\DatabaseResolver::class,
2020-06-08 02:35:30 +05:00
// 'source-health-monitor' => \App\Http\Middleware\SourceHealthMonitor::class
2018-08-16 02:29:25 +05:00
]);
2018-04-21 12:59:48 +05:00
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
$app->configure('database');
2019-05-11 11:43:55 +05:00
$app->configure('queue');
2020-05-21 08:28:18 +05:00
$app->configure('controller-to-table-mapping');
if (env('CACHING')) {
$app->configure('cache');
$app->register(Illuminate\Redis\RedisServiceProvider::class);
}
2019-05-11 11:43:55 +05:00
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
2018-04-21 12:59:48 +05:00
2019-05-10 06:57:42 +05:00
$guzzleClient = new \GuzzleHttp\Client();
$app->instance('GuzzleClient', $guzzleClient);
2019-05-11 11:43:55 +05:00
$jikan = new \Jikan\MyAnimeList\MalClient(app('GuzzleClient'));
2019-05-10 06:57:42 +05:00
$app->instance('JikanParser', $jikan);
if (env('SOURCE_BAD_HEALTH_FAILOVER') && env('DB_CACHING')) {
$app->register(\App\Providers\SourceHealthServiceProvider::class);
}
2019-07-17 04:11:19 +05:00
2019-11-15 10:52:05 -08:00
/**
* Load Blacklist into Redis
*/
2020-05-31 01:11:18 +05:00
//\App\HttpV3\Middleware\Blacklist::loadList(); causing issues on high load todo: add it as a one time init
2019-11-15 10:52:05 -08:00
2018-04-21 12:59:48 +05:00
/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/
2018-09-06 09:09:05 +05:00
$commonMiddleware = [
2020-05-21 08:28:18 +05:00
// 'blacklist',
// 'slave-auth',
// 'meta',
// 'etag',
'database-resolver',
// 'microcaching',
// 'cache-resolver',
// 'throttle'
2020-06-08 02:35:30 +05:00
// 'source-health-monitor'
2018-09-06 09:09:05 +05:00
];
2018-08-24 02:36:00 +05:00
2020-06-08 02:35:30 +05:00
//$app->router->group(
// [
// 'prefix' => 'v4',
// 'namespace' => 'App\Http\Controllers\V4',
// 'middleware' => $commonMiddleware
// ],
// function ($router) {
// require __DIR__.'/../routes/web.v4.php';
// }
//);
2019-04-26 02:21:39 +05:00
2018-08-11 21:34:36 +02:00
$app->router->group(
[
2018-08-16 00:46:27 +05:00
'prefix' => 'v3',
'namespace' => 'App\Http\Controllers\V3',
2018-08-24 02:36:00 +05:00
'middleware' => $commonMiddleware
2018-08-16 00:46:27 +05:00
],
function ($router) {
require __DIR__.'/../routes/web.v3.php';
}
);
$app->router->group(
[
2019-07-17 05:26:39 +05:00
'prefix' => '/',
'namespace' => 'App\Http\Controllers\V3',
'middleware' => $commonMiddleware
],
function ($router) {
$router->get('/', function () {
return response()->json([
'author_url' => 'http://irfan.dahir.co',
'discord_url' => 'https://discord.gg/4tvCr36',
2020-06-08 02:35:30 +05:00
'version' => '3.4',
'parser_version' => JIKAN_PARSER_VERSION,
'website_url' => 'https://jikan.moe',
'documentation_url' => 'https://jikan.docs.apiary.io',
'github_url' => 'https://github.com/jikan-me/jikan-me',
'parser_github_url' => 'https://github.com/jikan-me/jikan',
'production_api_url' => 'https://api.jikan.moe/v4/',
'status_url' => 'https://status.jikan.moe'
]);
});
2019-07-17 05:26:39 +05:00
}
);
$app->router->group(
[
'prefix' => 'v1',
2018-08-11 21:34:36 +02:00
],
function ($router) {
2019-07-17 04:58:42 +05:00
$router->get('/', function () {
return response()
->json([
'status' => 400,
'type' => 'HttpException',
'message' => 'This version is depreciated. Please check the documentation for the latest and supported versions.',
'error' => null
], 400);
});
2018-08-17 13:43:08 +05:00
}
);
$app->router->group(
[
2019-07-17 05:26:39 +05:00
'prefix' => 'v2',
2018-08-17 13:43:08 +05:00
],
function ($router) {
$router->get('/', function () {
2019-04-26 02:21:39 +05:00
return response()
->json([
'status' => 400,
'type' => 'HttpException',
2019-05-10 06:57:42 +05:00
'message' => 'This version is depreciated. Please check the documentation for the latest and supported versions.',
2019-04-26 02:21:39 +05:00
'error' => null
], 400);
2018-08-17 13:43:08 +05:00
});
}
);
2018-04-21 12:59:48 +05:00
return $app;