2018-04-21 12:59:48 +05:00
|
|
|
<?php
|
|
|
|
|
2021-06-15 09:20:29 +05:00
|
|
|
use App\Http\Middleware\SourceHeartbeatMonitor;
|
2020-07-05 11:29:11 +05:00
|
|
|
use App\Providers\SerializerFactory;
|
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';
|
2023-01-02 16:29:05 +00:00
|
|
|
require_once __DIR__.'/../app/Support/helpers.php';
|
2018-04-21 12:59:48 +05:00
|
|
|
|
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('JIKAN_PARSER_VERSION') or define('JIKAN_PARSER_VERSION', Versions::getVersion('jikan-me/jikan'));
|
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);
|
|
|
|
|
2021-09-11 19:36:27 +05:00
|
|
|
|
2018-08-16 02:29:25 +05:00
|
|
|
$app->withFacades();
|
2022-05-30 18:37:28 +01:00
|
|
|
|
|
|
|
$app->instance('path.config', app()->basePath() . DIRECTORY_SEPARATOR . 'config');
|
|
|
|
$app->instance('path.storage', app()->basePath() . DIRECTORY_SEPARATOR . 'storage');
|
|
|
|
|
2018-08-16 02:29:25 +05:00
|
|
|
$app->withEloquent();
|
2020-07-14 17:15:45 +05:00
|
|
|
$app->configure('swagger-lume');
|
2022-05-30 18:37:28 +01:00
|
|
|
$app->configure('scout');
|
2020-07-14 17:15:45 +05:00
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| 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.
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2021-09-11 03:39:49 +05:00
|
|
|
$globalMiddleware = [];
|
|
|
|
|
|
|
|
if (env('INSIGHTS', false)) {
|
|
|
|
$globalMiddleware[] = \App\Http\Middleware\Insights::class;
|
|
|
|
}
|
|
|
|
|
2023-05-21 16:10:21 +01:00
|
|
|
if (env('CORS_MIDDLEWARE', false)) {
|
2023-05-23 20:30:30 +01:00
|
|
|
$app->configure('cors');
|
2023-05-21 16:10:21 +01:00
|
|
|
$globalMiddleware[] = \App\Http\Middleware\CorsMiddleware::class;
|
|
|
|
}
|
|
|
|
|
2021-09-11 03:39:49 +05:00
|
|
|
$app->middleware($globalMiddleware);
|
|
|
|
|
2018-08-16 02:29:25 +05:00
|
|
|
$app->routeMiddleware([
|
2021-06-13 02:21:41 +05:00
|
|
|
'microcaching' => \App\Http\Middleware\MicroCaching::class,
|
2021-09-11 03:39:49 +05:00
|
|
|
'source-health-monitor' => SourceHeartbeatMonitor::class,
|
2023-01-24 23:30:47 +00:00
|
|
|
'cache-ttl' => \App\Http\Middleware\EndpointCacheTtlMiddleware::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.
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2021-06-13 04:05:33 +05:00
|
|
|
|
2022-12-03 03:06:12 +05:00
|
|
|
$app->configure('cache');
|
2019-04-26 00:55:05 +05:00
|
|
|
$app->configure('database');
|
2019-05-11 11:43:55 +05:00
|
|
|
$app->configure('queue');
|
2022-07-14 16:44:45 +01:00
|
|
|
$app->configure('roadrunner');
|
2023-01-02 16:29:05 +00:00
|
|
|
$app->configure('data');
|
2023-01-24 23:30:47 +00:00
|
|
|
$app->configure('jikan');
|
2020-05-21 08:28:18 +05:00
|
|
|
|
2022-07-14 16:44:45 +01:00
|
|
|
$app->register(\pushrbx\LumenRoadRunner\ServiceProvider::class);
|
2020-07-14 17:15:45 +05:00
|
|
|
$app->register(\SwaggerLume\ServiceProvider::class);
|
2019-06-19 01:34:47 +05:00
|
|
|
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
|
2021-06-13 04:05:33 +05:00
|
|
|
$app->register(\App\Providers\SourceHeartbeatProvider::class);
|
2022-07-14 16:44:45 +01:00
|
|
|
$app->register(\App\Providers\EventServiceProvider::class);
|
2022-06-05 18:53:53 +01:00
|
|
|
$app->register(\App\Providers\AppServiceProvider::class);
|
2022-12-03 03:06:12 +05:00
|
|
|
$app->register(Illuminate\Redis\RedisServiceProvider::class);
|
2023-01-02 16:29:05 +00:00
|
|
|
$app->register(Spatie\LaravelData\LaravelDataServiceProvider::class);
|
|
|
|
$app->register(\App\Providers\JikanEnumServiceProvider::class);
|
2021-07-17 23:05:59 +05:00
|
|
|
|
2022-12-03 03:06:12 +05:00
|
|
|
if (env('REPORTING') && strtolower(env('REPORTING_DRIVER')) === 'sentry') {
|
2021-09-11 19:36:27 +05:00
|
|
|
$app->register(\Sentry\Laravel\ServiceProvider::class);
|
|
|
|
// Sentry Performance Monitoring (optional)
|
|
|
|
$app->register(\Sentry\Laravel\Tracing\ServiceProvider::class);
|
2022-07-07 21:28:01 +05:00
|
|
|
|
|
|
|
\Sentry\configureScope(function (\Sentry\State\Scope $scope): void {
|
|
|
|
$scope->setTag('rest.jikan.version', env('APP_VERSION'));
|
|
|
|
$scope->setTag('parser.jikan.version', JIKAN_PARSER_VERSION);
|
|
|
|
});
|
2021-09-11 19:36:27 +05:00
|
|
|
}
|
|
|
|
|
2021-07-17 23:05:59 +05:00
|
|
|
$httpClient = \Symfony\Component\HttpClient\HttpClient::create(
|
|
|
|
[
|
|
|
|
'timeout' => env('SOURCE_TIMEOUT', 1)
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$app->instance('HttpClient', $httpClient);
|
2018-04-21 12:59:48 +05:00
|
|
|
|
2023-02-05 00:55:11 +00:00
|
|
|
$jikan = new \Jikan\MyAnimeList\MalClient($httpClient);
|
2019-05-10 06:57:42 +05:00
|
|
|
$app->instance('JikanParser', $jikan);
|
|
|
|
|
2020-07-05 11:29:11 +05:00
|
|
|
$app->instance('SerializerV4', SerializerFactory::createV4());
|
2022-05-30 18:37:28 +01:00
|
|
|
$app->register(Laravel\Scout\ScoutServiceProvider::class);
|
2022-06-08 17:02:05 +01:00
|
|
|
|
2023-05-01 16:52:52 +01:00
|
|
|
// we support TypeSense search index.
|
2022-06-21 20:55:36 +01:00
|
|
|
if (env("SCOUT_DRIVER") === "typesense") {
|
2022-06-08 17:02:05 +01:00
|
|
|
// in this case the TYPESENSE_HOST env var should be set too
|
2022-07-14 16:44:45 +01:00
|
|
|
$app->register(\Typesense\LaravelTypesense\TypesenseServiceProvider::class);
|
2022-06-08 17:02:05 +01:00
|
|
|
}
|
2023-05-01 16:52:52 +01:00
|
|
|
// experimental support for ElasticSearch search index
|
2022-06-08 17:02:05 +01:00
|
|
|
if (env("SCOUT_DRIVER") === "Matchish\ScoutElasticSearch\Engines\ElasticSearchEngine") {
|
|
|
|
// in this case the ELASTICSEARCH_HOST env var should be set too
|
|
|
|
$app->register(\Matchish\ScoutElasticSearch\ElasticSearchServiceProvider::class);
|
|
|
|
}
|
2020-07-05 11:29:11 +05:00
|
|
|
|
2021-06-21 09:41:32 +05: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 = [
|
2021-06-13 04:05:33 +05:00
|
|
|
'source-health-monitor',
|
2021-09-11 03:39:49 +05:00
|
|
|
'microcaching',
|
2023-01-24 23:30:47 +00:00
|
|
|
'cache-ttl'
|
2018-09-06 09:09:05 +05:00
|
|
|
];
|
2018-08-24 02:36:00 +05:00
|
|
|
|
2020-07-16 05:40:54 +05:00
|
|
|
|
2020-06-11 12:53:26 +05:00
|
|
|
$app->router->group(
|
|
|
|
[
|
2021-04-12 00:10:53 +05:00
|
|
|
'prefix' => 'v4',
|
2022-12-03 02:24:20 +05:00
|
|
|
'namespace' => 'App\Http\Controllers\V4DB',
|
2020-06-11 12:53:26 +05:00
|
|
|
'middleware' => $commonMiddleware
|
|
|
|
],
|
|
|
|
function ($router) {
|
|
|
|
require __DIR__.'/../routes/web.v4.php';
|
|
|
|
}
|
|
|
|
);
|
2019-04-26 02:21:39 +05:00
|
|
|
|
2018-08-16 00:46:27 +05:00
|
|
|
$app->router->group(
|
|
|
|
[
|
2019-07-17 05:26:39 +05:00
|
|
|
'prefix' => '/',
|
|
|
|
],
|
|
|
|
function ($router) {
|
2019-08-19 01:40:47 +05:00
|
|
|
$router->get('/', function () {
|
|
|
|
return response()->json([
|
2020-07-22 19:11:26 +05:00
|
|
|
'author_url' => 'https://github.com/irfan-dahir',
|
2020-07-05 11:29:11 +05:00
|
|
|
'discord_url' => 'http://discord.jikan.moe',
|
2021-04-12 00:10:33 +05:00
|
|
|
'version' => env('APP_VERSION'),
|
2020-04-25 10:38:03 +05:00
|
|
|
'parser_version' => JIKAN_PARSER_VERSION,
|
|
|
|
'website_url' => 'https://jikan.moe',
|
2020-07-22 19:11:26 +05:00
|
|
|
'documentation_url' => 'https://docs.api.jikan.moe/',
|
|
|
|
'github_url' => 'https://github.com/jikan-me/jikan-rest',
|
2020-04-25 10:38:03 +05:00
|
|
|
'parser_github_url' => 'https://github.com/jikan-me/jikan',
|
2021-04-12 00:10:33 +05:00
|
|
|
'production_api_url' => 'https://api.jikan.moe/v4/',
|
2021-06-13 04:05:33 +05:00
|
|
|
'status_url' => 'https://status.jikan.moe',
|
|
|
|
'myanimelist_heartbeat' => [
|
|
|
|
'status' => \App\Providers\SourceHeartbeatProvider::getHeartbeatStatus(),
|
|
|
|
'score' => \App\Providers\SourceHeartbeatProvider::getHeartbeatScore(),
|
|
|
|
'down' => \App\Providers\SourceHeartbeatProvider::isFailoverEnabled(),
|
|
|
|
'last_downtime' => \App\Providers\SourceHeartbeatProvider::getLastDowntime()
|
|
|
|
]
|
2019-08-19 01:40:47 +05:00
|
|
|
]);
|
|
|
|
});
|
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',
|
2020-09-07 04:10:01 +05:00
|
|
|
'message' => 'This version is discontinued. Please check the documentation for supported version(s).',
|
2019-07-17 04:58:42 +05:00
|
|
|
'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',
|
2020-09-07 04:10:01 +05:00
|
|
|
'message' => 'This version is discontinued. Please check the documentation for supported version(s).',
|
2019-04-26 02:21:39 +05:00
|
|
|
'error' => null
|
|
|
|
], 400);
|
2018-08-17 13:43:08 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-09-13 12:48:07 +05:00
|
|
|
$app->router->group(
|
|
|
|
[
|
|
|
|
'prefix' => 'v3',
|
|
|
|
],
|
|
|
|
function ($router) {
|
|
|
|
$router->get('/', function () {
|
|
|
|
return response()
|
|
|
|
->json([
|
|
|
|
'status' => 400,
|
|
|
|
'type' => 'HttpException',
|
|
|
|
'message' => 'This version is discontinued. Please check the documentation for supported version(s).',
|
|
|
|
'error' => null
|
|
|
|
], 400);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-04-21 12:59:48 +05:00
|
|
|
|
|
|
|
return $app;
|