You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB

  1. <?php
  2. chdir('..');
  3. include('vendor/autoload.php');
  4. register_shutdown_function('shutdown');
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. $router = new League\Route\RouteCollection;
  8. $templates = new League\Plates\Engine(dirname(__FILE__).'/../views');
  9. $router->addRoute('GET', '/', 'Main::index');
  10. $router->addRoute('GET', '/parse', 'Parse::parse');
  11. $router->addRoute('POST', '/parse', 'Parse::parse');
  12. $router->addRoute('POST', '/token', 'Token::token');
  13. $dispatcher = $router->getDispatcher();
  14. $request = Request::createFromGlobals();
  15. try {
  16. $response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
  17. $response->send();
  18. } catch(League\Route\Http\Exception\NotFoundException $e) {
  19. $response = new Response;
  20. $response->setStatusCode(404);
  21. $response->setContent("Not Found\n");
  22. $response->send();
  23. } catch(League\Route\Http\Exception\MethodNotAllowedException $e) {
  24. $response = new Response;
  25. $response->setStatusCode(405);
  26. $response->setContent("Method not allowed\n");
  27. $response->send();
  28. }
  29. function shutdown() {
  30. $error = error_get_last();
  31. if($error['type'] !== 0) {
  32. header('HTTP/1.1 500 Server Error');
  33. header('X-PHP-Error-Type: '.$error['type']);
  34. header('X-PHP-Error-Message: '.$error['message']);
  35. header('Content-Type: application/json');
  36. echo json_encode([
  37. 'error' => 'internal_error',
  38. 'error_code' => 500,
  39. 'error_description' => $error['message'],
  40. 'debug' => 'Please file an issue with any information you have about what caused this error: https://github.com/aaronpk/XRay/issues'
  41. ]);
  42. die();
  43. }
  44. }