Uses 2770K of libraries. Click here for Pure Java version (24060L/131K).
1 | !7 |
2 | |
3 | concept Domain { |
4 | S domain; |
5 | S moduleLibID; |
6 | bool mustBeEnabled; |
7 | |
8 | toString { ret super.toString() + " " + domain; } |
9 | } |
10 | |
11 | cmodule2 Eleu3 > DynEleu { |
12 | transient CRUD<Domain> domainCRUD; |
13 | switchable bool verbose; |
14 | switchable bool debugNanoHTTPD; |
15 | switchable S sameSite; |
16 | |
17 | start { |
18 | NanoHTTPD_debug = debugNanoHTTPD; |
19 | dbIndexingCI(Domain, 'domain); |
20 | uniqCI Domain(domain := "<default>"); |
21 | domainCRUD = new CRUD(Domain); |
22 | dm_registerAs eleuWithCRUD(); |
23 | } |
24 | |
25 | visualize { |
26 | var c = jtabs( |
27 | "Main", super.visualize(), |
28 | "Domains" := domainCRUD.visualize()); |
29 | |
30 | tablePopupMenu(domainCRUD.table(), voidfunc(JPopupMenu menu, int row) { |
31 | Domain d = domainCRUD.selected(), ret if null; |
32 | if (nempty(d.moduleLibID)) |
33 | addMenuItem(menu, "Load module", rThreadEnter { dm_makeOrShow(d.moduleLibID) }); |
34 | }); |
35 | |
36 | ret c; |
37 | } |
38 | |
39 | @Override |
40 | S moduleForDomain(S domain) { |
41 | domain = dropAfterColon(domain); // drop port number |
42 | for (Domain d : domainsInMatchingOrder()) { |
43 | if (domainIsUnder_extended(domain, d.domain)) { |
44 | S mod = findMod(d); |
45 | if (verbose) print("Domain matched: " + domain + " / " + d.domain + " => " + mod); |
46 | try answer mod; |
47 | } else |
48 | if (verbose) print("Domain not matched: " + domain + " / " + d.domain); |
49 | } |
50 | ret findMod(defaultDomain()); |
51 | } |
52 | |
53 | Domain defaultDomain() { |
54 | ret conceptWhereCI Domain(domain := "<default>"); |
55 | } |
56 | |
57 | S findMod(Domain d) { |
58 | if (d == null || empty(d.moduleLibID)) null; |
59 | ret d.mustBeEnabled |
60 | ? dm_findModuleWithParams(d.moduleLibID, enabled := true) |
61 | : dm_findModule(d.moduleLibID); |
62 | } |
63 | |
64 | ServeHttp_CookieHandler makeCookieHandler() { |
65 | ServeHttp_CookieHandler cookieHandler = super.makeCookieHandler(); |
66 | cookieHandler.metaParams = appendPrefixIfNempty("SameSite=", sameSite); |
67 | ret cookieHandler; |
68 | } |
69 | |
70 | // API |
71 | |
72 | Cl<Domain> domainsInMatchingOrder() { |
73 | ret sortByCalculatedFieldICDesc( |
74 | filter(list(Domain), d -> !eqic(d.domain, "<default>")), |
75 | d -> reversed(d.domain)); |
76 | } |
77 | |
78 | void addDomain(S domain, S moduleLibID, bool mustBeEnabled) { |
79 | uniq Domain(+domain, +moduleLibID, +mustBeEnabled); |
80 | } |
81 | } |
Began life as a copy of #1029618
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): bhatertpkbcr, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1032724 |
Snippet name: | Eleu with CRUD by domain - main web server module [backup before proxies] |
Eternal ID of this version: | #1032724/1 |
Text MD5: | ec50d1020d2538e6986c287cebc213d2 |
Transpilation MD5: | 205c599e6c77549483e674325032e949 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-03 23:14:41 |
Source code size: | 2282 bytes / 81 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 180 / 264 |
Referenced in: | [show references] |