@lango-project/lango-server 0.2.4 → 0.2.6
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/README.md +23 -5
- package/dist/body_reader.mjs.map +1 -1
- package/dist/builder.mjs.map +1 -1
- package/dist/cli/server.mjs +3 -838
- package/dist/cli/server.mjs.map +1 -1
- package/dist/client_identity.mjs.map +1 -1
- package/dist/database.mjs.map +1 -1
- package/dist/database_action.mjs.map +1 -1
- package/dist/database_options.mjs.map +1 -1
- package/dist/database_scope.mjs.map +1 -1
- package/dist/endpoint.mjs.map +1 -1
- package/dist/error_details.mjs.map +1 -1
- package/dist/execution_failure.mjs.map +1 -1
- package/dist/execution_identity.mjs.map +1 -1
- package/dist/execution_log.mjs.map +1 -1
- package/dist/execution_runtime.mjs.map +1 -1
- package/dist/execution_worker.mjs.map +1 -1
- package/dist/executor.mjs.map +1 -1
- package/dist/group.mjs.map +1 -1
- package/dist/http_failure.mjs.map +1 -1
- package/dist/job_configuration.mjs.map +1 -1
- package/dist/job_context.mjs.map +1 -1
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll_broker.mjs.map +1 -1
- package/dist/longpoll_options.mjs.map +1 -1
- package/dist/longpoll_session.mjs.map +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/module_loader.mjs.map +1 -1
- package/dist/options.mjs.map +1 -1
- package/dist/origin.mjs.map +1 -1
- package/dist/policy.mjs.map +1 -1
- package/dist/postgres_adapter.mjs.map +1 -1
- package/dist/postgres_worker.mjs.map +1 -1
- package/dist/queue_provider.mjs.map +1 -1
- package/dist/request_identity.mjs.map +1 -1
- package/dist/response.mjs +1 -1
- package/dist/response.mjs.map +1 -1
- package/dist/route_info.mjs +5 -1
- package/dist/route_info.mjs.map +1 -1
- package/dist/route_pattern.mjs.map +1 -1
- package/dist/routes.mjs +27 -4
- package/dist/routes.mjs.map +1 -1
- package/dist/runtime.mjs +66 -11
- package/dist/runtime.mjs.map +1 -1
- package/dist/server.mjs +2 -1
- package/dist/server.mjs.map +1 -1
- package/dist/server_context.mjs.map +1 -1
- package/dist/sqlite_adapter.mjs.map +1 -1
- package/dist/static_files.mjs.map +1 -1
- package/dist/token.mjs.map +1 -1
- package/dist/tokens.mjs +4 -1
- package/dist/tokens.mjs.map +1 -1
- package/dist/trace.mjs +6 -1
- package/dist/trace.mjs.map +1 -1
- package/dist/worker.mjs.map +1 -1
- package/docs/browser-sessions.md +96 -0
- package/examples/security/package.json +1 -1
- package/package.json +8 -5
- package/src/response.lango +1 -1
- package/src/route_info.lango +5 -2
- package/src/routes.lango +20 -3
- package/src/runtime.lango +56 -11
- package/src/server.lango +3 -2
- package/src/tokens.lango +4 -0
- package/src/trace.lango +5 -2
- package/dist/cli/.lango/bignumber.mjs +0 -3119
- package/dist/cli/.lango/localization.mjs +0 -108
- package/dist/cli/.lango/runtime.mjs +0 -725
- package/dist/cli/.lango/vendor/i18next.LICENSE +0 -21
- package/dist/cli/.lango/vendor/i18next.mjs +0 -2434
- package/dist/cli/.lango/xmldom/conventions.js +0 -429
- package/dist/cli/.lango/xmldom/dom-parser.js +0 -591
- package/dist/cli/.lango/xmldom/dom.js +0 -3759
- package/dist/cli/.lango/xmldom/entities.js +0 -2171
- package/dist/cli/.lango/xmldom/errors.js +0 -205
- package/dist/cli/.lango/xmldom/grammar.js +0 -559
- package/dist/cli/.lango/xmldom/index.js +0 -41
- package/dist/cli/.lango/xmldom/package.json +0 -1
- package/dist/cli/.lango/xmldom/sax.js +0 -983
- package/dist/cli/.lango/xmldom.LICENSE.md +0 -8
- package/dist/cli/body_reader.mjs +0 -180
- package/dist/cli/body_reader.mjs.map +0 -1
- package/dist/cli/client_identity.mjs +0 -250
- package/dist/cli/client_identity.mjs.map +0 -1
- package/dist/cli/database.mjs +0 -116
- package/dist/cli/database.mjs.map +0 -1
- package/dist/cli/database_options.mjs +0 -83
- package/dist/cli/database_options.mjs.map +0 -1
- package/dist/cli/database_scope.mjs +0 -93
- package/dist/cli/database_scope.mjs.map +0 -1
- package/dist/cli/endpoint.mjs +0 -50
- package/dist/cli/endpoint.mjs.map +0 -1
- package/dist/cli/error_details.mjs +0 -45
- package/dist/cli/error_details.mjs.map +0 -1
- package/dist/cli/longpoll_broker.mjs +0 -215
- package/dist/cli/longpoll_broker.mjs.map +0 -1
- package/dist/cli/longpoll_options.mjs +0 -103
- package/dist/cli/longpoll_options.mjs.map +0 -1
- package/dist/cli/longpoll_session.mjs +0 -136
- package/dist/cli/longpoll_session.mjs.map +0 -1
- package/dist/cli/middleware.mjs +0 -25
- package/dist/cli/middleware.mjs.map +0 -1
- package/dist/cli/options.mjs +0 -214
- package/dist/cli/options.mjs.map +0 -1
- package/dist/cli/origin.mjs +0 -87
- package/dist/cli/origin.mjs.map +0 -1
- package/dist/cli/policy.mjs +0 -121
- package/dist/cli/policy.mjs.map +0 -1
- package/dist/cli/postgres_adapter.mjs +0 -178
- package/dist/cli/postgres_adapter.mjs.map +0 -1
- package/dist/cli/route_pattern.mjs +0 -129
- package/dist/cli/route_pattern.mjs.map +0 -1
- package/dist/cli/routes.mjs +0 -360
- package/dist/cli/routes.mjs.map +0 -1
- package/dist/cli/sqlite_adapter.mjs +0 -163
- package/dist/cli/sqlite_adapter.mjs.map +0 -1
- package/dist/cli/static_files.mjs +0 -224
- package/dist/cli/static_files.mjs.map +0 -1
- package/dist/cli/trace.mjs +0 -53
- package/dist/cli/trace.mjs.map +0 -1
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import { trace } from "./trace.mjs";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import * as files from "serve-static";
|
|
5
|
-
import {
|
|
6
|
-
hostGlobal as __hostGlobal,
|
|
7
|
-
hostGlobalCall as __hostGlobalCall,
|
|
8
|
-
bindContexts as __bindContexts,
|
|
9
|
-
isNumber as __isNumber,
|
|
10
|
-
isString as __isString,
|
|
11
|
-
isBool as __isBool,
|
|
12
|
-
isObject as __isObject,
|
|
13
|
-
isArray as __isArray,
|
|
14
|
-
entries as __entries,
|
|
15
|
-
requireBoolean as __requireBoolean,
|
|
16
|
-
normalize as __normalize,
|
|
17
|
-
finite as __finite,
|
|
18
|
-
call as __call,
|
|
19
|
-
boundary as __boundary,
|
|
20
|
-
requireArity as __requireArity,
|
|
21
|
-
withArity as __withArity,
|
|
22
|
-
} from "./.lango/runtime.mjs";
|
|
23
|
-
|
|
24
|
-
export class StaticFiles {
|
|
25
|
-
#settings;
|
|
26
|
-
#serve;
|
|
27
|
-
#runtime;
|
|
28
|
-
constructor(settings) {
|
|
29
|
-
__requireArity(arguments.length, [0], "constructor");
|
|
30
|
-
settings = __boundary(settings);
|
|
31
|
-
this.#settings = settings;
|
|
32
|
-
if (__requireBoolean(!__requireBoolean(__normalize(__normalize(fs.statSync(__normalize(settings.directory))).isDirectory())))) {
|
|
33
|
-
throw "Static directory must be a directory";
|
|
34
|
-
}
|
|
35
|
-
if (__requireBoolean(__requireBoolean(__normalize(settings.fallback) !== null) && __requireBoolean(!__requireBoolean(__normalize(__normalize(fs.statSync(__normalize(path.join(__normalize(settings.directory), __normalize(settings.fallback))))).isFile()))))) {
|
|
36
|
-
throw "Static fallback must be a file";
|
|
37
|
-
}
|
|
38
|
-
this.#serve = __normalize(files.default(__normalize(settings.directory), { index: __normalize(settings.index), dotfiles: "deny", fallthrough: false, redirect: false }));
|
|
39
|
-
this.#runtime = __normalize(files.default(__normalize(settings.directory), { index: false, dotfiles: "allow", fallthrough: false, redirect: false }));
|
|
40
|
-
}
|
|
41
|
-
receive(req, res, failed) {
|
|
42
|
-
__requireArity(arguments.length, [0, 1, 2], "receive");
|
|
43
|
-
req = __boundary(req);
|
|
44
|
-
res = __boundary(res);
|
|
45
|
-
failed = __boundary(failed);
|
|
46
|
-
let mount = __normalize(this.#settings.path);
|
|
47
|
-
let url = __normalize(req.url);
|
|
48
|
-
let pathname = __normalize(__normalize(url.split("?"))[0]);
|
|
49
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(mount !== "/") && __requireBoolean(pathname !== mount)) && __requireBoolean(!__requireBoolean(__normalize(pathname.startsWith(`${mount}/`)))))) {
|
|
50
|
-
__call(failed, 404, "NotFound");
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
if (__requireBoolean(mount !== "/")) {
|
|
54
|
-
req.url = __normalize(url.slice(__normalize(mount.length)));
|
|
55
|
-
if (__requireBoolean(__requireBoolean(__normalize(req.url) === "") || __requireBoolean(__normalize(req.url.startsWith("?"))))) {
|
|
56
|
-
req.url = `/${__normalize(req.url)}`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
let local = __normalize(__normalize(req.url.split("?"))[0]);
|
|
60
|
-
let decoded = null;
|
|
61
|
-
try {
|
|
62
|
-
decoded = __hostGlobalCall(["decodeURIComponent"], local);
|
|
63
|
-
} catch (error) {
|
|
64
|
-
__call(failed, 400, "InvalidPath");
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
if (__requireBoolean(__requireBoolean(__normalize(decoded.includes("\\"))) || __requireBoolean(__normalize(decoded.includes(__normalize(__hostGlobal(["String"]).fromCharCode(0))))))) {
|
|
68
|
-
__call(failed, 400, "InvalidPath");
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
let segments = __normalize(decoded.split("/"));
|
|
72
|
-
let runtime = false;
|
|
73
|
-
for (const [index, segment] of __entries(segments)) {
|
|
74
|
-
if (__requireBoolean(__normalize(segment.startsWith(".")))) {
|
|
75
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(index === 1) && __requireBoolean(segment === ".lango")) && __requireBoolean(__normalize(this.#settings.runtime)))) {
|
|
76
|
-
runtime = true;
|
|
77
|
-
} else {
|
|
78
|
-
__call(failed, 403, "Forbidden");
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
let done = __withArity(__bindContexts((error) => {
|
|
84
|
-
error = __boundary(error);
|
|
85
|
-
this.#failure(req, res, failed, error, decoded);
|
|
86
|
-
return null;
|
|
87
|
-
}), [0], "closure");
|
|
88
|
-
let serve = __normalize(this.#serve);
|
|
89
|
-
if (__requireBoolean(runtime)) {
|
|
90
|
-
serve = __normalize(this.#runtime);
|
|
91
|
-
}
|
|
92
|
-
trace(`Static ${__normalize(req.method)} ${pathname}: directory=${__normalize(this.#settings.directory)}; index=${__normalize(this.#settings.index)}; runtime=${runtime}`);
|
|
93
|
-
__call(serve, req, res, done);
|
|
94
|
-
return null;
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
#failure(req, res, failed, error, pathname = null) {
|
|
98
|
-
__requireArity(arguments.length, [0, 1, 2, 3], "failure");
|
|
99
|
-
req = __boundary(req);
|
|
100
|
-
res = __boundary(res);
|
|
101
|
-
failed = __boundary(failed);
|
|
102
|
-
error = __boundary(error);
|
|
103
|
-
pathname = __boundary(pathname);
|
|
104
|
-
if (__requireBoolean(__normalize(res.headersSent))) {
|
|
105
|
-
__normalize(res.destroy());
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
let status = 404;
|
|
109
|
-
let code = "NotFound";
|
|
110
|
-
if (__requireBoolean(error !== null)) {
|
|
111
|
-
if (__normalize(error.status) === 400) {
|
|
112
|
-
status = 400;
|
|
113
|
-
code = "InvalidPath";
|
|
114
|
-
} else if (__normalize(error.status) === 403) {
|
|
115
|
-
status = 403;
|
|
116
|
-
code = "Forbidden";
|
|
117
|
-
} else if (__normalize(error.status) === 416) {
|
|
118
|
-
status = 416;
|
|
119
|
-
code = "RangeNotSatisfiable";
|
|
120
|
-
} else if (__normalize(error.status) === 404) {
|
|
121
|
-
status = 404;
|
|
122
|
-
} else {
|
|
123
|
-
status = 500;
|
|
124
|
-
code = "InternalServerError";
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(status === 404) && __requireBoolean(pathname !== null)) && __requireBoolean(__normalize(this.#settings.fallback) !== null)) && __requireBoolean(!__requireBoolean(__normalize(pathname.startsWith("/.lango"))))) && __requireBoolean(__normalize(path.posix.extname(pathname)) === "")) && __requireBoolean(acceptsHTML(req.headers.accept)))) {
|
|
128
|
-
req.url = `/${__normalize(this.#settings.fallback)}`;
|
|
129
|
-
let done = __withArity(__bindContexts((error) => {
|
|
130
|
-
error = __boundary(error);
|
|
131
|
-
this.#failure(req, res, failed, error);
|
|
132
|
-
return null;
|
|
133
|
-
}), [0], "closure");
|
|
134
|
-
let serve = __normalize(this.#serve);
|
|
135
|
-
__call(serve, req, res, done);
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
__call(failed, status, code);
|
|
139
|
-
return null;
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
export function staticOptions(root, spec) {
|
|
144
|
-
__requireArity(arguments.length, [0, 1], "staticOptions");
|
|
145
|
-
root = __boundary(root);
|
|
146
|
-
spec = __boundary(spec);
|
|
147
|
-
if (__requireBoolean(spec === null)) {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(spec))) || __requireBoolean(__isArray(spec)))) {
|
|
151
|
-
throw "static must be a map";
|
|
152
|
-
}
|
|
153
|
-
let allowed = ["path", "directory", "index", "fallback", "runtime"];
|
|
154
|
-
for (const [key, value] of __entries(spec)) {
|
|
155
|
-
if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(key))))) {
|
|
156
|
-
throw `Unknown static option: ${key}`;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
let mount = __normalize(spec.path);
|
|
160
|
-
if (__requireBoolean(mount === null)) {
|
|
161
|
-
mount = "/";
|
|
162
|
-
}
|
|
163
|
-
let pattern = new (__hostGlobal(["RegExp"]))("^/(?:[A-Za-z0-9_-]+/)*[A-Za-z0-9_-]*$");
|
|
164
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(mount))) || __requireBoolean(!__requireBoolean(__normalize(pattern.test(mount)))))) {
|
|
165
|
-
throw "Static path must be an absolute URL prefix";
|
|
166
|
-
}
|
|
167
|
-
if (__requireBoolean(__requireBoolean(mount !== "/") && __requireBoolean(__normalize(mount.endsWith("/"))))) {
|
|
168
|
-
mount = __normalize(mount.slice(0, __finite(-1)));
|
|
169
|
-
}
|
|
170
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.directory)))) || __requireBoolean(__normalize(spec.directory.trim()) === ""))) {
|
|
171
|
-
throw "Static directory is required";
|
|
172
|
-
}
|
|
173
|
-
let index = __normalize(spec.index);
|
|
174
|
-
if (__requireBoolean(index === null)) {
|
|
175
|
-
index = "index.html";
|
|
176
|
-
}
|
|
177
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(index))) || __requireBoolean(index === "")) || __requireBoolean(__normalize(index.startsWith(".")))) || __requireBoolean(__normalize(index.includes("/")))) || __requireBoolean(__normalize(index.includes("\\"))))) {
|
|
178
|
-
throw "Static index must be a file name";
|
|
179
|
-
}
|
|
180
|
-
let fallback = __normalize(spec.fallback);
|
|
181
|
-
if (__requireBoolean(__requireBoolean(fallback !== null) && __requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(fallback))) || __requireBoolean(fallback === "")) || __requireBoolean(__normalize(fallback.startsWith(".")))) || __requireBoolean(__normalize(fallback.includes("/")))) || __requireBoolean(__normalize(fallback.includes("\\")))))) {
|
|
182
|
-
throw "Static fallback must be a file name";
|
|
183
|
-
}
|
|
184
|
-
let runtime = __normalize(spec.runtime);
|
|
185
|
-
if (__requireBoolean(__requireBoolean(runtime === null) || __requireBoolean(runtime === "false"))) {
|
|
186
|
-
runtime = false;
|
|
187
|
-
}
|
|
188
|
-
if (__requireBoolean(runtime === "true")) {
|
|
189
|
-
runtime = true;
|
|
190
|
-
}
|
|
191
|
-
if (__requireBoolean(!__requireBoolean(__isBool(runtime)))) {
|
|
192
|
-
throw "Static runtime must be boolean";
|
|
193
|
-
}
|
|
194
|
-
return { path: mount, directory: __normalize(path.resolve(root, __normalize(spec.directory))), index: index, fallback: fallback, runtime: runtime };
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function acceptsHTML(value) {
|
|
199
|
-
__requireArity(arguments.length, [0], "acceptsHTML");
|
|
200
|
-
value = __boundary(value);
|
|
201
|
-
if (__requireBoolean(!__requireBoolean(__isString(value)))) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
let zero = new (__hostGlobal(["RegExp"]))("^q\\s*=\\s*0(?:\\.0*)?$", "i");
|
|
205
|
-
for (const range of __normalize(value.split(","))) {
|
|
206
|
-
let parts = __normalize(range.split(";"));
|
|
207
|
-
let media = __normalize(parts[0]);
|
|
208
|
-
let type = __normalize(__normalize(media.trim()).toLowerCase());
|
|
209
|
-
if (__requireBoolean(__requireBoolean(type === "text/html") || __requireBoolean(type === "application/xhtml+xml"))) {
|
|
210
|
-
let allowed = true;
|
|
211
|
-
for (const parameter of __normalize(parts.slice(1))) {
|
|
212
|
-
if (__requireBoolean(__normalize(zero.test(__normalize(parameter.trim()))))) {
|
|
213
|
-
allowed = false;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (__requireBoolean(allowed)) {
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return false;
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
//# sourceMappingURL=static_files.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"static_files.mjs","sources":["static_files.lango"],"sourcesContent":["import \"./trace\"\n trace(message)\nimport js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js \"serve-static\" as files\nimport js global RegExp\nimport js global decodeURIComponent\nimport js global String\n\nexport staticOptions(root, spec)\nexport class StaticFiles(settings)\n methods\n receive(req, res, failed)\n\nstaticOptions(root, spec)\n if spec == null\n return null\n if !is_object(spec) or is_array(spec)\n throw \"static must be a map\"\n allowed = [\"path\", \"directory\", \"index\", \"fallback\", \"runtime\"]\n for spec as key: value\n if !allowed.includes(key)\n throw \"Unknown static option: ${key}\"\n mount = spec.path\n if mount == null\n mount = \"/\"\n pattern = new RegExp(\"^/(?:[A-Za-z0-9_-]+/)*[A-Za-z0-9_-]*$\")\n if !is_string(mount) or !pattern.test(mount)\n throw \"Static path must be an absolute URL prefix\"\n if mount != \"/\" and mount.endsWith(\"/\")\n mount = mount.slice(0, -1)\n if !is_string(spec.directory) or spec.directory.trim() == \"\"\n throw \"Static directory is required\"\n index = spec.index\n if index == null\n index = \"index.html\"\n if !is_string(index) or index == \"\" or index.startsWith(\".\") or index.includes(\"/\") or index.includes(\"\\\\\")\n throw \"Static index must be a file name\"\n fallback = spec.fallback\n if fallback != null and (!is_string(fallback) or fallback == \"\" or fallback.startsWith(\".\") or fallback.includes(\"/\") or fallback.includes(\"\\\\\"))\n throw \"Static fallback must be a file name\"\n runtime = spec.runtime\n if runtime == null or runtime == \"false\"\n runtime = false\n if runtime == \"true\"\n runtime = true\n if !is_bool(runtime)\n throw \"Static runtime must be boolean\"\n return {\n path: mount\n directory: path/resolve(root, spec.directory)\n index: index\n fallback: fallback\n runtime: runtime\n }\n\nStaticFiles(settings)\n @settings = settings\n if !fs/statSync(settings.directory).isDirectory()\n throw \"Static directory must be a directory\"\n if settings.fallback != null and !fs/statSync(path/join(settings.directory, settings.fallback)).isFile()\n throw \"Static fallback must be a file\"\n @serve = files/default(settings.directory, {\n index: settings.index\n dotfiles: \"deny\"\n fallthrough: false\n redirect: false\n })\n @runtime = files/default(settings.directory, {\n index: false\n dotfiles: \"allow\"\n fallthrough: false\n redirect: false\n })\n\nStaticFiles:receive(req, res, failed)\n mount = @settings.path\n url = req.url\n pathname = url.split(\"?\")[0]\n if mount != \"/\" and pathname != mount and !pathname.startsWith(\"${mount}/\")\n failed(404, \"NotFound\")\n return null\n if mount != \"/\"\n req.url = url.slice(mount.length)\n if req.url == \"\" or req.url.startsWith(\"?\")\n req.url = \"/${req.url}\"\n local = req.url.split(\"?\")[0]\n decoded = null\n try\n decoded = decodeURIComponent(local)\n catch error\n failed(400, \"InvalidPath\")\n return null\n if decoded.includes(\"\\\\\") or decoded.includes(String/fromCharCode(0))\n failed(400, \"InvalidPath\")\n return null\n segments = decoded.split(\"/\")\n runtime = false\n for segments as index: segment\n if segment.startsWith(\".\")\n if index == 1 and segment == \".lango\" and @settings.runtime\n runtime = true\n else\n failed(403, \"Forbidden\")\n return null\n done = (error)\n capture req\n capture res\n capture failed\n capture decoded\n failure(req, res, failed, error, decoded)\n serve = @serve\n if runtime\n serve = @runtime\n trace(\"Static ${req.method} ${pathname}: directory=${@settings.directory}; index=${@settings.index}; runtime=${runtime}\")\n serve(req, res, done)\n return null\n\nStaticFiles:failure(req, res, failed, error, pathname = null)\n if res.headersSent\n res.destroy()\n return null\n status = 404\n code = \"NotFound\"\n if error != null\n switch error.status\n case 400\n status = 400\n code = \"InvalidPath\"\n case 403\n status = 403\n code = \"Forbidden\"\n case 416\n status = 416\n code = \"RangeNotSatisfiable\"\n case 404\n status = 404\n else\n status = 500\n code = \"InternalServerError\"\n if status == 404 and pathname != null and @settings.fallback != null and !pathname.startsWith(\"/.lango\") and path/posix/extname(pathname) == \"\" and acceptsHTML(req.headers.accept)\n req.url = \"/${@settings.fallback}\"\n done = (error)\n capture req\n capture res\n capture failed\n failure(req, res, failed, error)\n serve = @serve\n serve(req, res, done)\n return null\n failed(status, code)\n return null\n\nacceptsHTML(value)\n if !is_string(value)\n return false\n zero = new RegExp(\"^q\\\\s*=\\\\s*0(?:\\\\.0*)?$\", \"i\")\n for value.split(\",\") as range\n parts = range.split(\";\")\n media = parts[0]\n type = media.trim().toLowerCase()\n if type == \"text/html\" or type == \"application/xhtml+xml\"\n allowed = true\n for parts.slice(1) as parameter\n if zero.test(parameter.trim())\n allowed = false\n if allowed\n return true\n return false\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2IA;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cli/trace.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
contextGet as __contextGet,
|
|
3
|
-
contextSet as __contextSet,
|
|
4
|
-
contextRestore as __contextRestore,
|
|
5
|
-
requireBoolean as __requireBoolean,
|
|
6
|
-
normalize as __normalize,
|
|
7
|
-
boundary as __boundary,
|
|
8
|
-
requireArity as __requireArity,
|
|
9
|
-
} from "./.lango/runtime.mjs";
|
|
10
|
-
|
|
11
|
-
export function trace(message) {
|
|
12
|
-
const __contextScope = [];
|
|
13
|
-
try {
|
|
14
|
-
__requireArity(arguments.length, [0], "trace");
|
|
15
|
-
message = __boundary(message);
|
|
16
|
-
if (__requireBoolean(__normalize(__contextGet("log").verbose) === true)) {
|
|
17
|
-
__normalize(__contextGet("log").debug(message));
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
return null;
|
|
21
|
-
} finally {
|
|
22
|
-
__contextRestore(__contextScope);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function responseLog(id, method, path, status) {
|
|
27
|
-
const __contextScope = [];
|
|
28
|
-
try {
|
|
29
|
-
__requireArity(arguments.length, [0, 1, 2, 3], "responseLog");
|
|
30
|
-
id = __boundary(id);
|
|
31
|
-
method = __boundary(method);
|
|
32
|
-
path = __boundary(path);
|
|
33
|
-
status = __boundary(status);
|
|
34
|
-
let message = `HTTP ${method} ${path} completed status=${status}`;
|
|
35
|
-
if (__requireBoolean(id !== null)) {
|
|
36
|
-
message = `[${id}] ${message}`;
|
|
37
|
-
}
|
|
38
|
-
if (__requireBoolean(status >= 500)) {
|
|
39
|
-
__normalize(__contextGet("log").err(message));
|
|
40
|
-
} else {
|
|
41
|
-
if (__requireBoolean(status >= 400)) {
|
|
42
|
-
__normalize(__contextGet("log").warn(message));
|
|
43
|
-
} else {
|
|
44
|
-
trace(message);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
return null;
|
|
49
|
-
} finally {
|
|
50
|
-
__contextRestore(__contextScope);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=trace.mjs.map
|
package/dist/cli/trace.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trace.mjs","sources":["trace.lango"],"sourcesContent":["export trace(message)\nexport responseLog(id, method, path, status)\n\ntrace(message)\n context log\n if log.verbose? == true\n log.debug(message)\n return null\n\n\nresponseLog(id, method, path, status)\n context log\n message = \"HTTP ${method} ${path} completed status=${status}\"\n if id != null\n message = \"[${id}] ${message}\"\n if status >= 500\n log.err(message)\n else\n if status >= 400\n log.warn(message)\n else\n trace(message)\n return null\n"],"names":[],"mappings":";;;;;;;;;;AAGA;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|