rtjscomp 0.8.5 → 0.8.7
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/package.json +1 -1
- package/rtjscomp.js +50 -47
package/package.json
CHANGED
package/rtjscomp.js
CHANGED
|
@@ -42,6 +42,7 @@ const file_privates = new Set;
|
|
|
42
42
|
const file_blocks = new Set;
|
|
43
43
|
/// any path -> file
|
|
44
44
|
const path_aliases = new Map;
|
|
45
|
+
const path_aliases_reverse = new Map;
|
|
45
46
|
const path_aliases_templates = new Map;
|
|
46
47
|
const services = new Set;
|
|
47
48
|
/// compiled file handlers
|
|
@@ -446,39 +447,39 @@ const request_handle = async (request, response, https) => {
|
|
|
446
447
|
let path_params = null;
|
|
447
448
|
let request_body_promise = null;
|
|
448
449
|
|
|
450
|
+
if (path_aliases_reverse.has(path)) {
|
|
451
|
+
response.setHeader('Location', path_aliases_reverse.get(path));
|
|
452
|
+
throw 301;
|
|
453
|
+
}
|
|
449
454
|
if (path_aliases.has(path)) {
|
|
450
|
-
|
|
451
|
-
'Content-Location',
|
|
452
|
-
path = path_aliases.get(path)
|
|
453
|
-
);
|
|
455
|
+
path = path_aliases.get(path)
|
|
454
456
|
}
|
|
455
457
|
else { // aliases with *
|
|
456
458
|
const path_split = path.split('/');
|
|
457
|
-
const templates = path_aliases_templates.get(
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
continue template;
|
|
459
|
+
const templates = path_aliases_templates.get(
|
|
460
|
+
path_split.shift()
|
|
461
|
+
);
|
|
462
|
+
if (templates != null)
|
|
463
|
+
template: for (const template of templates) {
|
|
464
|
+
const template_path = template.path_split;
|
|
465
|
+
const template_path_length = template_path.length;
|
|
466
|
+
if (template_path_length !== path_split.length) continue;
|
|
467
|
+
const params = {};
|
|
468
|
+
for (let i = 0; i < template_path_length; ++i) {
|
|
469
|
+
if (template_path[i].charCodeAt(0) === 42) {
|
|
470
|
+
if (template_path[i].length > 1) {
|
|
471
|
+
params[
|
|
472
|
+
template_path[i].slice(1)
|
|
473
|
+
] = path_split[i];
|
|
473
474
|
}
|
|
474
475
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
);
|
|
479
|
-
path_params = params;
|
|
480
|
-
break;
|
|
476
|
+
else if (template_path[i] !== path_split[i]) {
|
|
477
|
+
continue template;
|
|
478
|
+
}
|
|
481
479
|
}
|
|
480
|
+
path = template.value;
|
|
481
|
+
path_params = params;
|
|
482
|
+
break;
|
|
482
483
|
}
|
|
483
484
|
}
|
|
484
485
|
|
|
@@ -504,11 +505,9 @@ const request_handle = async (request, response, https) => {
|
|
|
504
505
|
!file_raws.has(path)
|
|
505
506
|
);
|
|
506
507
|
|
|
507
|
-
if (
|
|
508
|
-
if (
|
|
509
|
-
|
|
510
|
-
'content-length' in request_headers
|
|
511
|
-
) {
|
|
508
|
+
if (request_method !== 'GET') {
|
|
509
|
+
if (!file_dyn_enabled) throw 405;
|
|
510
|
+
if ('content-length' in request_headers) {
|
|
512
511
|
request_body_promise = new Promise(resolve => {
|
|
513
512
|
const request_body_chunks = [];
|
|
514
513
|
request.on('data', chunk => {
|
|
@@ -521,9 +520,6 @@ const request_handle = async (request, response, https) => {
|
|
|
521
520
|
});
|
|
522
521
|
}
|
|
523
522
|
}
|
|
524
|
-
else if (request_method !== 'GET') {
|
|
525
|
-
throw 400;
|
|
526
|
-
}
|
|
527
523
|
|
|
528
524
|
let file_function = null;
|
|
529
525
|
let file_stat = null;
|
|
@@ -939,12 +935,13 @@ file_keep_new(PATH_CONFIG + 'services.txt', data => (
|
|
|
939
935
|
));
|
|
940
936
|
|
|
941
937
|
await Promise.all([
|
|
942
|
-
file_keep_new(PATH_CONFIG + 'init.js', data => {
|
|
938
|
+
file_keep_new(PATH_CONFIG + 'init.js', async data => {
|
|
943
939
|
if (!data) return;
|
|
944
940
|
log('[deprecated] run global init script');
|
|
945
941
|
try {
|
|
946
|
-
|
|
947
|
-
|
|
942
|
+
await (
|
|
943
|
+
new AsyncFunction('require', data)
|
|
944
|
+
)(custom_require);
|
|
948
945
|
}
|
|
949
946
|
catch (err) {
|
|
950
947
|
log('[error] init.js: ' + err.message);
|
|
@@ -958,20 +955,26 @@ await Promise.all([
|
|
|
958
955
|
}),
|
|
959
956
|
file_keep_new(PATH_CONFIG + 'path_aliases.txt', data => {
|
|
960
957
|
map_generate_equ(path_aliases, data);
|
|
958
|
+
path_aliases_reverse.clear();
|
|
961
959
|
path_aliases_templates.clear();
|
|
962
960
|
for (const [key, value] of path_aliases.entries()) {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
961
|
+
if (key.includes('*')) {
|
|
962
|
+
path_aliases.delete(key);
|
|
963
|
+
const path_split = key.split('/');
|
|
964
|
+
const first = path_split.shift();
|
|
965
|
+
if (path_aliases_templates.has(first)) {
|
|
966
|
+
path_aliases_templates.get(first).push(
|
|
967
|
+
{path_split, value}
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
path_aliases_templates.set(first, [
|
|
972
|
+
{path_split, value},
|
|
973
|
+
]);
|
|
974
|
+
}
|
|
970
975
|
}
|
|
971
976
|
else {
|
|
972
|
-
|
|
973
|
-
[template, value],
|
|
974
|
-
]);
|
|
977
|
+
path_aliases_reverse.set(value, key);
|
|
975
978
|
}
|
|
976
979
|
}
|
|
977
980
|
}),
|