diff --git a/build/router/controller/js.php b/build/router/controller/js.php new file mode 100644 index 0000000..591a94d --- /dev/null +++ b/build/router/controller/js.php @@ -0,0 +1,78 @@ + Calling URI + * + */ + public function __construct($url){ + $this->page = isset($url['page']) ? $url['page'] : ''; + $this->page = preg_match('/^@[a-z]+$/', $this->page) ? substr($this->page, 1) : null; + } + + + /* Generate _SERVER.js + * + */ + public function server(){ + header('Content-Type: text/javascript; charset=utf-8'); + + echo "window._SERVER = ".json_encode([ + + 'session' => [ + 'name' => $_SESSION['NAME'], + 'connected' => isset($_SESSION['USER']) ? count($_SESSION['USER']) > 0 : false + ] + + ])."\n"; + + } + + + /* Manage bundle hash + * + */ + public function bundle(){ + if( is_null($this->page) ){ + http_response_code(404); + die(); + } + + /* (1) Extract /public_html/js/ all .js files */ + $js_scripts = glob(__PUBLIC__.'/js/bundle/'.$this->page.'@*.js'); + + /* (2) If match pattern 'bundle@home@*.js' */ + foreach($js_scripts as $fname){ + + $bname = basename($fname); + + // if match -> load it and exit + header("Location: /js/bundle/$bname"); + die(); + + } + + /* (3) If nothing found */ + http_response_code(404); + die(); + + } + + /* POST-CALL + * + */ + public function __destruct(){ + + } + + + + } diff --git a/build/router/controller/page.php b/build/router/controller/page.php index 9a132d5..867c427 100644 --- a/build/router/controller/page.php +++ b/build/router/controller/page.php @@ -15,7 +15,6 @@ */ public function __construct($url){ $this->pagename = $url['page']; - } @@ -23,8 +22,8 @@ * */ public function load(){ - if( file_exists(__PUBLIC__."/view/".$this->pagename.".php") ) - include __PUBLIC__."/view/".$this->pagename.".php"; + if( file_exists(__PUBLIC__."/page/".$this->pagename.".php") ) + include __PUBLIC__."/page/".$this->pagename.".php"; else echo "page not found"; } diff --git a/build/router/controller/redirect.php b/build/router/controller/redirect.php index 7b10307..42cf86e 100644 --- a/build/router/controller/redirect.php +++ b/build/router/controller/redirect.php @@ -18,8 +18,8 @@ /* CALL * */ - public function homepage(){ - header('Location: /homepage/'); + public function home(){ + header('Location: /home/'); } /* POST-CALL diff --git a/config/routes.json b/config/routes.json index 8019426..d92fda3 100644 --- a/config/routes.json +++ b/config/routes.json @@ -5,6 +5,21 @@ "routes": { + + "/js/_SERVER.js": { + "methods": ["GET"], + "controller": "js:server", + "arguments": {} + }, + + "/js/bundle{page}.js": { + "methods": ["GET"], + "controller": "js:bundle", + "arguments": { + "page":"@[a-z]+" + } + }, + "/{page}/": { "methods": ["GET"], "controller": "page:load", @@ -23,7 +38,7 @@ "/{any}": { "methods": ["GET"], - "controller": "redirect:homepage", + "controller": "redirect:home", "arguments": { "any": ".*" } diff --git a/public_html/page/home.php b/public_html/page/home.php new file mode 100644 index 0000000..a3235d6 --- /dev/null +++ b/public_html/page/home.php @@ -0,0 +1,35 @@ + + +
+ + + + + + +