plugin/vhosting: use same format for fields as for exports.config. Mixing can be confusing for who's reading.

Massimo Melina committed Apr 27, 2022 at 16:00 UTC 655cb3460f37d977cd89e3946ef21bb4131a1ad1
1 file changed +12 -7
plugins/vhosting/plugin.js
+12 -7
@@ -3,25 +3,30 @@ exports.version = 1
3 exports.apiRequired = 2 // 2 is for the config 'array'
4
5 exports.config = {
6 - hosts: { label: '', type: 'array', height: 300, fields: [
7 - { k: 'host', label: "Domain" },
8 - { k: 'path', helperText: "Root path in VFS" },
9 - ] }
6 + hosts: {
7 + label: '',
8 + type: 'array',
9 + fields: {
10 + host: { label: "Domain" },
11 + root: { helperText: "Root path in VFS" },
12 + },
13 + height: 300,
14 + }
15 }
16
17 exports.init = api => ({
18 middleware(ctx) {
19 let toModify = ctx
15 - if (ctx.path.startsWith(api.const.SPECIAL_URI)) {
20 + if (ctx.path.startsWith(api.const.SPECIAL_URI)) { // special uris should be excluded...
21 toModify = ctx.request.query
17 - if (toModify.path === undefined)
22 + if (toModify.path === undefined) // ...unless they carry a path in the query. In that case we'll work that.
23 return
24 }
25 const hosts = api.getConfig('hosts')
26 if (!hosts) return
27 for (const row of hosts)
28 if (ctx.host === row.host) {
24 - toModify.path = row.path + toModify.path
29 + toModify.path = row.root + toModify.path
30 return
31 }
32 }