added js dep. '/js/_SERVER.js' generated by the router.controller.js.server() method

This commit is contained in:
xdrm-brackets 2017-11-30 16:45:26 +01:00
parent d043c83ead
commit 2e7291929a
4 changed files with 77 additions and 24 deletions

View File

@ -0,0 +1,65 @@
<?php
namespace router\controller;
class js{
private $pagename;
/* PRE-CALL
*
* @url<String> Calling URI
*
*/
public function __construct($url){
}
/* Generate _SERVER.js
*
*/
public function server(){
header('Content-Type: text/javascript; charset=utf-8');
echo "window._SERVER = ".json_encode([
'a' => [1, 2]
])."\n";
}
/* Manage bundle hash
*
*/
public function bundle(){
/* (1) Extract /public_html/js/ all .js files */
$js_scripts = glob(__PUBLIC__.'/js/*.js');
/* (2) If match pattern 'bundle@*.js' */
foreach($js_scripts as $fname){
$bname = basename($fname);
// if match -> load it and exit
if( preg_match('/bundle@[\da-f]+\.js/', $bname) )
header("Location: /js/$bname");
}
}
/* POST-CALL
*
*/
public function __destruct(){
}
}

View File

@ -14,8 +14,8 @@
* *
*/ */
public function __construct($url){ public function __construct($url){
$this->pagename = isset($url['page']) ? $url['page'] : null;
$this->pagename = $url['page'];
} }
@ -30,28 +30,6 @@
echo "page not found"; echo "page not found";
} }
/* Manage bundle hash
*
*/
public function bundle(){
/* (1) Extract /public_html/js/ all .js files */
$js_scripts = glob(__PUBLIC__.'/js/*.js');
/* (2) If match pattern 'bundle@*.js' */
foreach($js_scripts as $fname){
$bname = basename($fname);
// if match -> load it and exit
if( preg_match('/bundle@[\da-f]+\.js/', $bname) )
header("Location: /js/$bname");
}
}
/* POST-CALL /* POST-CALL
* *
*/ */

View File

@ -7,7 +7,13 @@
"/js/bundle.js": { "/js/bundle.js": {
"methods": ["GET"], "methods": ["GET"],
"controller": "page:bundle", "controller": "js:bundle",
"arguments": {}
},
"/js/_SERVER.js": {
"methods": ["GET"],
"controller": "js:server",
"arguments": {} "arguments": {}
}, },

View File

@ -13,6 +13,10 @@
<link rel='shortcut icon' href='/favicon.ico'> <link rel='shortcut icon' href='/favicon.ico'>
<!-- CSS dependencies --> <!-- CSS dependencies -->
<link rel='stylesheet' type='text/css' href='/css/layout.css'>
<!-- JS dependencies -->
<script type='text/javascript' src='/js/_SERVER.js'></script>
</head> </head>
<body> <body>