DefaultController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Class DefaultController
  4. * @author Blackbinbin
  5. */
  6. class DefaultController extends BaseController {
  7. public function __construct() {
  8. parent::__construct(true);
  9. }
  10. /**
  11. * 判断ip,输出首页
  12. */
  13. public function actionIndex() {
  14. // if (ENV != ENV_DEV) {
  15. // header('Location: https://dice.eosget.io/#/box');
  16. // Response::exitMsg('');
  17. // } else {
  18. // // 清除无效的cookie
  19. // Account::checkToken();
  20. //
  21. // if (ENV != ENV_DEV) {
  22. // $GLOBALS['eosProtocol'] = "https";
  23. // $GLOBALS['eosHost'] = "api.eosbeijing.one";
  24. // $GLOBALS['eosPort'] = 443;
  25. // }
  26. $this->tpl->display('index');
  27. // }
  28. }
  29. /**
  30. * 判断ip,输出首页
  31. */
  32. public function actionMini() {
  33. $this->tpl->display('mini');
  34. }
  35. /**
  36. * 判断ip,输出首页
  37. */
  38. public function actionSw() {
  39. // 不需要默认头部信息
  40. $GLOBALS['FORBID_ORIGIN'] = true;
  41. $path = BASE_DIR . 'dist/sw.js';
  42. // 增加浏览器缓存
  43. $filemd5 = md5_file($path);
  44. $this->_addEtag($filemd5);
  45. $content = file_get_contents($path);
  46. header("Content-Type: application/javascript; charset=utf-8");
  47. Response::exitMsg($content, CODE_SUCCESS, null, true);
  48. }
  49. private function _addEtag($etag) {
  50. // always send headers
  51. header("Etag: $etag");
  52. // exit if not modified
  53. if (@trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
  54. header("HTTP/1.1 304 Not Modified");
  55. Response::exitMsg('', CODE_SUCCESS, '304 Not Modified');
  56. }
  57. }
  58. }