@wxn0brp/falcon-frame 0.5.2 → 0.5.4
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/dist/index.js +20 -6
- package/dist/render.js +2 -2
- package/dist/res.js +1 -1
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27,9 +27,9 @@ export class FalconFrame extends Router {
|
|
|
27
27
|
this.addBodyParser(json(this, { limit: this.opts.bodyLimit }));
|
|
28
28
|
if (!this.opts.disableUrlencodedParser)
|
|
29
29
|
this.addBodyParser(urlencoded(this, { limit: this.opts.bodyLimit }));
|
|
30
|
-
this.engine(".html", (path, options, callback) => {
|
|
30
|
+
this.engine(".html", (path, options, callback, FF) => {
|
|
31
31
|
try {
|
|
32
|
-
const content = renderHTML(path, options);
|
|
32
|
+
const content = renderHTML(path, options, [], FF);
|
|
33
33
|
callback(null, content);
|
|
34
34
|
}
|
|
35
35
|
catch (e) {
|
|
@@ -43,15 +43,30 @@ export class FalconFrame extends Router {
|
|
|
43
43
|
}
|
|
44
44
|
listen(port, callback, beforeHandleRequest) {
|
|
45
45
|
const server = http.createServer(this.getApp(beforeHandleRequest));
|
|
46
|
+
let parsedPort = 0;
|
|
47
|
+
let host = "";
|
|
48
|
+
if (typeof port === "string") {
|
|
49
|
+
if (port.includes(":")) {
|
|
50
|
+
const [h, po] = port.split(":");
|
|
51
|
+
host = h;
|
|
52
|
+
parsedPort = +po;
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
parsedPort = +port;
|
|
56
|
+
}
|
|
57
|
+
else if (typeof port === "number") {
|
|
58
|
+
parsedPort = port;
|
|
59
|
+
}
|
|
46
60
|
if (typeof callback === "boolean") {
|
|
47
61
|
if (callback)
|
|
48
62
|
callback = () => {
|
|
49
|
-
console.log(`[FF] Server running on http
|
|
63
|
+
console.log(`[FF] Server running on http://${host || "localhost"}:${parsedPort}`);
|
|
50
64
|
};
|
|
51
65
|
else
|
|
52
66
|
callback = () => { };
|
|
53
67
|
}
|
|
54
|
-
|
|
68
|
+
const cb = callback || (() => { });
|
|
69
|
+
server.listen(parsedPort, host || "0.0.0.0", cb);
|
|
55
70
|
return server;
|
|
56
71
|
}
|
|
57
72
|
getApp(beforeHandleRequest) {
|
|
@@ -65,9 +80,8 @@ export class FalconFrame extends Router {
|
|
|
65
80
|
};
|
|
66
81
|
}
|
|
67
82
|
engine(ext, callback) {
|
|
68
|
-
if (ext[0] !== ".")
|
|
83
|
+
if (ext[0] !== ".")
|
|
69
84
|
ext = "." + ext;
|
|
70
|
-
}
|
|
71
85
|
this.engines[ext] = callback;
|
|
72
86
|
return this;
|
|
73
87
|
}
|
package/dist/render.js
CHANGED
|
@@ -20,7 +20,7 @@ export function renderHTML(templatePath, data, renderedPaths = [], FF) {
|
|
|
20
20
|
return renderHTML(partialPath, data, [
|
|
21
21
|
...renderedPaths,
|
|
22
22
|
realPath,
|
|
23
|
-
]);
|
|
23
|
+
], FF);
|
|
24
24
|
});
|
|
25
25
|
// Layout
|
|
26
26
|
if (FF && FF.vars["layout"]) {
|
|
@@ -31,7 +31,7 @@ export function renderHTML(templatePath, data, renderedPaths = [], FF) {
|
|
|
31
31
|
return template;
|
|
32
32
|
if (!hasHtmlStructure && forceNoLayout)
|
|
33
33
|
return template;
|
|
34
|
-
return renderHTML(FF.vars["layout"], { ...data, body: template }, [...renderedPaths, realPath]);
|
|
34
|
+
return renderHTML(FF.vars["layout"], { ...data, body: template }, [...renderedPaths, realPath], FF);
|
|
35
35
|
}
|
|
36
36
|
return template;
|
|
37
37
|
}
|
package/dist/res.js
CHANGED
|
@@ -137,7 +137,7 @@ export class FFResponse extends http.ServerResponse {
|
|
|
137
137
|
this.ct(opts.contentType || "text/html");
|
|
138
138
|
this.end(str);
|
|
139
139
|
}
|
|
140
|
-
});
|
|
140
|
+
}, opts.notShareFF ? undefined : this.FF);
|
|
141
141
|
}
|
|
142
142
|
catch (err) {
|
|
143
143
|
ff.logger.error(`Unhandled error in template engine: ${err}`);
|
package/dist/types.d.ts
CHANGED
|
@@ -61,11 +61,12 @@ export interface StaticServeOptions {
|
|
|
61
61
|
errorIfDirNotFound?: boolean;
|
|
62
62
|
notRenderHtml?: boolean;
|
|
63
63
|
}
|
|
64
|
-
export type EngineCallback = (path: string, options: any, callback: (e: any, rendered?: string) => void) => void;
|
|
64
|
+
export type EngineCallback = (path: string, options: any, callback: (e: any, rendered?: string) => void, FF?: FalconFrame) => void;
|
|
65
65
|
export interface RenderOptions {
|
|
66
66
|
notUseViews?: boolean;
|
|
67
67
|
contentType?: string;
|
|
68
68
|
baseDir?: string;
|
|
69
69
|
engine?: string;
|
|
70
70
|
notAppendExt?: boolean;
|
|
71
|
+
notShareFF?: boolean;
|
|
71
72
|
}
|