free-framework 4.6.2 ā 4.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/commands/new.js +2 -9
- package/package.json +1 -1
- package/runtime/server.js +28 -11
package/cli/commands/new.js
CHANGED
|
@@ -48,13 +48,6 @@ module.exports = function (name) {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
// Wrap up
|
|
51
|
-
console.log("\n
|
|
52
|
-
|
|
53
|
-
execSync("npm install", { cwd: targetDir, stdio: "inherit" });
|
|
54
|
-
console.log("\nā
Enterprise Project Scaffolded Successfully!");
|
|
55
|
-
console.log(`\nTo get started, run:\n cd ${name}\n free serve\n`);
|
|
56
|
-
} catch (err) {
|
|
57
|
-
console.log("\nā ļø Scaffolding complete, but npm install failed. Please run 'npm install' manually.");
|
|
58
|
-
console.log(`\nTo get started, run:\n cd ${name}\n npm install\n free serve\n`);
|
|
59
|
-
}
|
|
51
|
+
console.log("\nā
Enterprise Project Scaffolded Successfully!");
|
|
52
|
+
console.log(`\nTo get started, run:\n cd ${name}\n npm install\n free serve\n`);
|
|
60
53
|
}
|
package/package.json
CHANGED
package/runtime/server.js
CHANGED
|
@@ -15,37 +15,53 @@ const { LRUCache } = require('lru-cache');
|
|
|
15
15
|
|
|
16
16
|
class FreeServer {
|
|
17
17
|
constructor() {
|
|
18
|
+
console.log(`[Free Engine] āļø Runtime Core v4.6.5 initializing...`);
|
|
18
19
|
this.app = new HyperExpress.Server();
|
|
19
20
|
this.viewsPath = process.env.VIEWS_PATH || nodePath.join(process.cwd(), 'views');
|
|
20
21
|
this.namedMiddlewares = {};
|
|
21
22
|
this.errorViews = {};
|
|
22
23
|
this.plugins = [];
|
|
23
24
|
|
|
24
|
-
//
|
|
25
|
+
// 1. Absolute Top Logger
|
|
26
|
+
this.app.use((req, res, next) => {
|
|
27
|
+
console.log(`[Free Engine] š„ [${new Date().toLocaleTimeString()}] Incoming: ${req.method} ${req.url}`);
|
|
28
|
+
|
|
29
|
+
// Track response
|
|
30
|
+
const start = Date.now();
|
|
31
|
+
res.on('finish', () => {
|
|
32
|
+
console.log(`[Free Engine] š¤ [${new Date().toLocaleTimeString()}] Sent: ${req.method} ${req.url} (${res.statusCode}) - ${Date.now() - start}ms`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (typeof next === 'function') {
|
|
36
|
+
return next();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// 2. Global Error Handler
|
|
25
41
|
this.app.set_error_handler((req, res, error) => {
|
|
26
42
|
console.error(`[Free Engine] š„ Global Uncaught Error:`, error);
|
|
27
43
|
this.handleError(req, res, error);
|
|
28
44
|
});
|
|
29
45
|
|
|
30
|
-
|
|
31
|
-
console.log(`[Free Engine] š„ Request: ${req.method} ${req.url}`);
|
|
32
|
-
if (next) next();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// Static Asset Serving Middleware
|
|
46
|
+
// 3. Static Asset Serving (Simplified & Safe)
|
|
36
47
|
const publicPath = nodePath.join(process.cwd(), 'public');
|
|
37
48
|
this.app.use((req, res, next) => {
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
if (req.path === '/' || !req.path.includes('.')) {
|
|
50
|
+
return typeof next === 'function' ? next() : null;
|
|
51
|
+
}
|
|
40
52
|
|
|
53
|
+
const lookupPath = req.path.startsWith('/') ? req.path.substring(1) : req.path;
|
|
41
54
|
const fullPath = nodePath.join(publicPath, lookupPath);
|
|
55
|
+
|
|
42
56
|
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile()) {
|
|
57
|
+
console.log(`[Free Engine] š Serving static: ${lookupPath}`);
|
|
43
58
|
const ext = nodePath.extname(fullPath);
|
|
44
59
|
const mimes = { '.js': 'application/javascript', '.css': 'text/css', '.png': 'image/png', '.jpg': 'image/jpeg', '.svg': 'image/svg+xml' };
|
|
45
60
|
res.type(mimes[ext] || 'text/plain');
|
|
46
61
|
return res.send(fs.readFileSync(fullPath));
|
|
47
62
|
}
|
|
48
|
-
|
|
63
|
+
|
|
64
|
+
if (typeof next === 'function') next();
|
|
49
65
|
});
|
|
50
66
|
|
|
51
67
|
this.app.get('/test-static', (req, res) => res.send('Static serving test'));
|
|
@@ -179,7 +195,8 @@ class FreeServer {
|
|
|
179
195
|
|
|
180
196
|
start(port = 3000) {
|
|
181
197
|
this.app.get('/health', (req, res) => res.send('OK'));
|
|
182
|
-
|
|
198
|
+
console.log(`[Free Engine] š” Binding to 127.0.0.1:${port}...`);
|
|
199
|
+
this.app.listen(port, '127.0.0.1').then(() => {
|
|
183
200
|
const blueUnderline = "\x1b[34m\x1b[4m";
|
|
184
201
|
const reset = "\x1b[0m";
|
|
185
202
|
console.log(`ā” Free Engine Ignite: ${blueUnderline}http://localhost:${port}${reset}`);
|