Skip to content

Commit 9d0a3eb

Browse files
committed
Browser sync configuration update
1 parent 659a928 commit 9d0a3eb

File tree

4 files changed

+80
-9
lines changed

4 files changed

+80
-9
lines changed

.bs-config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
const config = require('./config.json'); // carica la porta dal file JSON
2+
13
module.exports = {
2-
proxy: 'localhost:8000',
4+
proxy: `localhost:${config.PORT}`,
35
files: [
6+
'./**/*.php',
47
'src/**/*.php',
58
'src/**/*.css',
69
'src/**/*.js',
@@ -12,6 +15,8 @@ module.exports = {
1215
'locales/**/*.txt',
1316
'css/**/*.cs',
1417
'js/**/*.cs',
18+
'config/**/*.php',
19+
1520
],
1621
open: true,
1722
notify: true,

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@
2121
"ext-openssl": "*",
2222
"ext-gd": "*"
2323
},
24-
"autoload": {
24+
"scripts": {
25+
"dev": "node start-dev.js"
26+
},
27+
"scripts-descriptions": {
28+
"dev": "Start PHP server + BrowserSync concurrently"
29+
},
30+
"autoload": {
2531
"psr-4": {
2632
"\\": "/"
2733
}
2834
}
29-
}
35+
}

index.php

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,70 @@
4545
use framework\Loader;
4646
use framework\Dispatcher;
4747

48-
/* Set classes auto loader simply by instantiating framework Loader */
49-
$loader = new Loader();
48+
try {
49+
// Set classes autoloader simply by instantiating the framework Loader
50+
$loader = new Loader();
5051

51-
/* Create a dispatcher for handling URL request to the appropriate user controller */
52-
$dispatcher = new Dispatcher();
53-
$dispatcher->dispatch();
52+
// Create a Dispatcher to dispatch URL request to the appropriate user controller
53+
$dispatcher = new Dispatcher();
54+
$dispatcher->dispatch();
5455

56+
} catch (\Throwable $th) {
57+
58+
//throw throwable;
59+
printCatch($th);
60+
} catch (Exception $e) {
61+
62+
//throw exception;
63+
printCatch($e);
64+
}
65+
66+
function printCatch($e)
67+
{
68+
$html = <<<HTML
69+
<!doctype html>
70+
<html lang="en">
71+
<head>
72+
<meta charset="utf-8">
73+
<title>PHP Error</title>
74+
<meta name="viewport" content="width=device-width, initial-scale=1">
75+
<!-- Bootstrap 5 CDN -->
76+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
77+
</head>
78+
<div class="container">
79+
<body class="bg-white text-light">
80+
<div class="container py-5">
81+
<div class="alert bg-dark shadow-lg">
82+
<h1 class="display-5 fw-bold text-danger">
83+
<i class="bi bi-bug-fill"></i> Error!
84+
</h1>
85+
<hr class="border-light">
86+
<p>
87+
<span class="badge bg-warning text-dark">File</span>
88+
<code class="h3">{$e->getFile()}</code>
89+
</p>
90+
<p>
91+
<span class="badge bg-info text-dark">Line</span>
92+
<code class="h2" >{$e->getLine()}</code>
93+
</p>
94+
<hr>
95+
<p class="lead text-light">
96+
<span class="badge bg-danger text-dark">Error info</span><br>
97+
<code class="text-warning h2">{$e->getMessage()}</code>
98+
</p>
99+
<button class="btn btn-outline-light mt-3" onclick="location.reload()">🔁 Reload page</button>
100+
</div>
101+
</div>
102+
<div class="alert bg-dark shadow-lg">
103+
<div class="text-center text-yellow bg-dark">
104+
PHP WEB MVC Framework - [
105+
<a href="https://github.com/rcarvello/webmvcframework/wiki">Wiki Pages</a> |
106+
<a href="https://github.com/rcarvello/webmvcframework">GitHub</a> ]
107+
</div>
108+
</body>
109+
</div>
110+
</html>
111+
HTML;
112+
echo $html;
113+
}
55114

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dev": "browser-sync start --config .bs-config.js"
66
},
77
"devDependencies": {
8-
"browser-sync": "2.29.3"
8+
"browser-sync": "2.29.3",
9+
"concurrently": "^8.2.0"
910
}
1011
}

0 commit comments

Comments
 (0)