vhosting plugin

Massimo Melina committed Apr 26, 2022 at 19:46 UTC 6f5f2d858f0045c8acbb9c5c77bd5905b78ceec6
1 file changed +28
plugins/vhosting/plugin.js new
+28
@@ -0,0 +1,28 @@
1 +exports.description = "If you want to have different home folders, based on domain"
2 +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 + ] }
10 +}
11 +
12 +exports.init = api => ({
13 + middleware(ctx) {
14 + let toModify = ctx
15 + if (ctx.path.startsWith(api.const.SPECIAL_URI)) {
16 + toModify = ctx.request.query
17 + if (toModify.path === undefined)
18 + return
19 + }
20 + const hosts = api.getConfig('hosts')
21 + if (!hosts) return
22 + for (const row of hosts)
23 + if (ctx.host === row.host) {
24 + toModify.path = row.path + toModify.path
25 + return
26 + }
27 + }
28 +})