hfs 0.52.6 → 0.52.7-rc2
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/src/const.js +1 -1
- package/src/roots.js +19 -13
package/package.json
CHANGED
package/src/const.js
CHANGED
|
@@ -45,7 +45,7 @@ exports.DEV = process.env.DEV || exports.argv.dev ? 'DEV' : '';
|
|
|
45
45
|
exports.ORIGINAL_CWD = process.cwd();
|
|
46
46
|
exports.HFS_STARTED = new Date();
|
|
47
47
|
const PKG_PATH = (0, path_1.join)(__dirname, '..', 'package.json');
|
|
48
|
-
exports.BUILD_TIMESTAMP = "2024-05-
|
|
48
|
+
exports.BUILD_TIMESTAMP = "2024-05-12T16:27:50.053Z";
|
|
49
49
|
const pkg = JSON.parse(fs.readFileSync(PKG_PATH, 'utf8'));
|
|
50
50
|
exports.VERSION = pkg.version;
|
|
51
51
|
exports.RUNNING_BETA = exports.VERSION.includes('-');
|
package/src/roots.js
CHANGED
|
@@ -24,11 +24,12 @@ const rootsMiddleware = (ctx, next) => (() => {
|
|
|
24
24
|
if (ctx.path.startsWith(misc_1.SPECIAL_URI)) { // special uris should be excluded...
|
|
25
25
|
if (!ctx.path.startsWith(misc_1.API_URI))
|
|
26
26
|
return; // ...unless it's an api
|
|
27
|
+
params = ctx.state.params || ctx.query; // for api we'll translate params
|
|
28
|
+
changeUriParams(v => (0, misc_1.removeStarting)(ctx.state.revProxyPath, v)); // removal must be done before adding the root
|
|
27
29
|
let { referer } = ctx.headers;
|
|
28
30
|
referer && (referer = new URL(referer).pathname);
|
|
29
31
|
if (referer === null || referer === void 0 ? void 0 : referer.startsWith(ctx.state.revProxyPath + misc_1.ADMIN_URI))
|
|
30
32
|
return; // exclude apis for admin-panel
|
|
31
|
-
params = ctx.state.params || ctx.query; // for api we'll translate params
|
|
32
33
|
}
|
|
33
34
|
if (lodash_1.default.isEmpty(exports.roots.get()))
|
|
34
35
|
return;
|
|
@@ -44,19 +45,24 @@ const rootsMiddleware = (ctx, next) => (() => {
|
|
|
44
45
|
(0, connections_1.disconnect)(ctx, 'bad-domain');
|
|
45
46
|
return true; // true will avoid calling next
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
+ (0, misc_1.removeStarting)(removePrefix, b); // removal must be done before adding the root
|
|
48
|
+
changeUriParams(v => join(root, v));
|
|
49
|
+
if (!params)
|
|
50
|
+
ctx.path = join(root, ctx.path);
|
|
51
|
+
function changeUriParams(cb) {
|
|
52
|
+
if (!params)
|
|
53
|
+
return;
|
|
54
|
+
for (const [k, v] of Object.entries(params))
|
|
55
|
+
if (k.startsWith('uri'))
|
|
56
|
+
params[k] = Array.isArray(v) ? v.map(cb) : cb(v);
|
|
57
57
|
}
|
|
58
58
|
})() || next();
|
|
59
59
|
exports.rootsMiddleware = rootsMiddleware;
|
|
60
|
-
function join(a, b) {
|
|
61
|
-
|
|
60
|
+
function join(a, b, joiner = '/') {
|
|
61
|
+
if (!b)
|
|
62
|
+
return a;
|
|
63
|
+
if (!a)
|
|
64
|
+
return b;
|
|
65
|
+
const ends = a.at(-1) === joiner;
|
|
66
|
+
const starts = b[0] === joiner;
|
|
67
|
+
return a + (!ends && !starts ? joiner + b : ends && starts ? b.slice(1) : b);
|
|
62
68
|
}
|