@adaas/a-server 0.0.20 → 0.0.22
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/dist/index.d.mts +126 -10
- package/dist/index.d.ts +126 -10
- package/dist/index.js +504 -230
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +507 -225
- package/dist/index.mjs.map +1 -1
- package/examples/simple-server/concept.ts +8 -1
- package/package.json +2 -2
- package/src/components/A-ServerProxy/A-ServerProxy.component.ts +8 -7
- package/src/components/A-StaticLoader/A-StaticLoader.component.ts +220 -49
- package/src/components/A-StaticLoader/A-StaticLoader.component.types.ts +5 -107
- package/src/containers/A-Service/A-Service.container.ts +38 -18
- package/src/context/A-StaticConfig/A-StaticConfig.context.ts +192 -9
- package/src/entities/A-Request/A-Request.entity.ts +1 -1
- package/src/entities/A-Request/A-Request.entity.types.ts +1 -1
- package/src/entities/A-Response/A-Response.entity.ts +1 -1
- package/src/entities/A-Response/A-Response.entity.types.ts +1 -1
- package/tsconfig.build.json +0 -28
|
@@ -1,36 +1,219 @@
|
|
|
1
1
|
import { A_Fragment } from "@adaas/a-concept";
|
|
2
2
|
import { A_Route } from "@adaas/a-server/entities/A-Route/A-Route.entity";
|
|
3
3
|
|
|
4
|
+
export interface A_StaticAlias {
|
|
5
|
+
alias: string;
|
|
6
|
+
path: string;
|
|
7
|
+
directory: string;
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
}
|
|
4
10
|
|
|
11
|
+
export interface A_StaticDirectoryConfig {
|
|
12
|
+
path: string;
|
|
13
|
+
directory: string;
|
|
14
|
+
alias?: string;
|
|
15
|
+
}
|
|
5
16
|
|
|
6
17
|
export class A_StaticConfig extends A_Fragment {
|
|
7
18
|
|
|
8
|
-
readonly directories: Array<string
|
|
19
|
+
readonly directories: Array<string>;
|
|
20
|
+
private _aliases: Map<string, A_StaticAlias> = new Map();
|
|
21
|
+
private _directoryConfigs: A_StaticDirectoryConfig[] = [];
|
|
9
22
|
|
|
10
23
|
constructor(
|
|
11
24
|
/**
|
|
12
25
|
* Setup directories to serve static files from, comma separated
|
|
13
26
|
*/
|
|
14
|
-
directories: string[] = []
|
|
27
|
+
directories: string[] = [],
|
|
28
|
+
/**
|
|
29
|
+
* Custom directory configurations with aliases
|
|
30
|
+
*/
|
|
31
|
+
directoryConfigs: A_StaticDirectoryConfig[] = []
|
|
15
32
|
) {
|
|
16
33
|
super();
|
|
17
34
|
|
|
18
35
|
this.directories = directories;
|
|
36
|
+
this._directoryConfigs = directoryConfigs;
|
|
37
|
+
|
|
38
|
+
// Initialize default aliases from directories
|
|
39
|
+
this.initializeDefaultAliases();
|
|
40
|
+
|
|
41
|
+
// Initialize custom aliases from directoryConfigs
|
|
42
|
+
this.initializeCustomAliases();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private initializeDefaultAliases(): void {
|
|
46
|
+
this.directories.forEach((dir, index) => {
|
|
47
|
+
const alias: A_StaticAlias = {
|
|
48
|
+
alias: `/static${index > 0 ? index : ''}`,
|
|
49
|
+
path: `/static${index > 0 ? index : ''}`,
|
|
50
|
+
directory: dir,
|
|
51
|
+
enabled: true
|
|
52
|
+
};
|
|
53
|
+
this._aliases.set(alias.path, alias);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private initializeCustomAliases(): void {
|
|
58
|
+
this._directoryConfigs.forEach((config) => {
|
|
59
|
+
const alias: A_StaticAlias = {
|
|
60
|
+
alias: config.alias || config.path,
|
|
61
|
+
path: config.path,
|
|
62
|
+
directory: config.directory,
|
|
63
|
+
enabled: true
|
|
64
|
+
};
|
|
65
|
+
this._aliases.set(alias.path, alias);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Add a custom static file alias
|
|
71
|
+
* @param alias - The URL path alias (e.g., '/assets')
|
|
72
|
+
* @param directory - The local directory path
|
|
73
|
+
* @param path - Optional custom path (defaults to alias)
|
|
74
|
+
*/
|
|
75
|
+
public addAlias(alias: string, directory: string, path?: string): void {
|
|
76
|
+
const staticAlias: A_StaticAlias = {
|
|
77
|
+
alias,
|
|
78
|
+
path: path || alias,
|
|
79
|
+
directory,
|
|
80
|
+
enabled: true
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
this._aliases.set(staticAlias.path, staticAlias);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Remove a static file alias
|
|
88
|
+
* @param aliasPath - The path of the alias to remove
|
|
89
|
+
*/
|
|
90
|
+
public removeAlias(aliasPath: string): boolean {
|
|
91
|
+
return this._aliases.delete(aliasPath);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Enable or disable an alias
|
|
96
|
+
* @param aliasPath - The path of the alias
|
|
97
|
+
* @param enabled - Whether to enable or disable
|
|
98
|
+
*/
|
|
99
|
+
public setAliasEnabled(aliasPath: string, enabled: boolean): boolean {
|
|
100
|
+
const alias = this._aliases.get(aliasPath);
|
|
101
|
+
if (alias) {
|
|
102
|
+
alias.enabled = enabled;
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get all configured aliases
|
|
110
|
+
*/
|
|
111
|
+
public getAliases(): A_StaticAlias[] {
|
|
112
|
+
return Array.from(this._aliases.values());
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get enabled aliases only
|
|
117
|
+
*/
|
|
118
|
+
public getEnabledAliases(): A_StaticAlias[] {
|
|
119
|
+
return Array.from(this._aliases.values()).filter(alias => alias.enabled !== false);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Find the best matching alias for a given request path
|
|
124
|
+
* @param requestPath - The request path to match
|
|
125
|
+
*/
|
|
126
|
+
public findMatchingAlias(requestPath: string): A_StaticAlias | null {
|
|
127
|
+
let bestMatch: A_StaticAlias | null = null;
|
|
128
|
+
let longestMatch = 0;
|
|
129
|
+
|
|
130
|
+
for (const alias of this.getEnabledAliases()) {
|
|
131
|
+
if (requestPath.startsWith(alias.path) && alias.path.length > longestMatch) {
|
|
132
|
+
bestMatch = alias;
|
|
133
|
+
longestMatch = alias.path.length;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return bestMatch;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Check if an alias exists
|
|
142
|
+
* @param aliasPath - The path to check
|
|
143
|
+
*/
|
|
144
|
+
public hasAlias(aliasPath: string): boolean {
|
|
145
|
+
return this._aliases.has(aliasPath);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get a specific alias by path
|
|
150
|
+
* @param aliasPath - The path of the alias
|
|
151
|
+
*/
|
|
152
|
+
public getAlias(aliasPath: string): A_StaticAlias | undefined {
|
|
153
|
+
return this._aliases.get(aliasPath);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Add multiple aliases at once
|
|
158
|
+
* @param aliases - Array of alias configurations
|
|
159
|
+
*/
|
|
160
|
+
public addAliases(aliases: A_StaticDirectoryConfig[]): void {
|
|
161
|
+
aliases.forEach(config => {
|
|
162
|
+
this.addAlias(config.alias || config.path, config.directory, config.path);
|
|
163
|
+
});
|
|
19
164
|
}
|
|
20
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Clear all aliases
|
|
168
|
+
*/
|
|
169
|
+
public clearAliases(): void {
|
|
170
|
+
this._aliases.clear();
|
|
171
|
+
}
|
|
21
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Update an existing alias
|
|
175
|
+
* @param aliasPath - The path of the alias to update
|
|
176
|
+
* @param updates - Partial updates to apply
|
|
177
|
+
*/
|
|
178
|
+
public updateAlias(aliasPath: string, updates: Partial<A_StaticAlias>): boolean {
|
|
179
|
+
const alias = this._aliases.get(aliasPath);
|
|
180
|
+
if (alias) {
|
|
181
|
+
Object.assign(alias, updates);
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
22
186
|
|
|
23
187
|
/**
|
|
24
|
-
*
|
|
25
|
-
|
|
188
|
+
* Get statistics about configured aliases
|
|
189
|
+
*/
|
|
190
|
+
public getStats(): {
|
|
191
|
+
total: number;
|
|
192
|
+
enabled: number;
|
|
193
|
+
disabled: number;
|
|
194
|
+
directories: string[];
|
|
195
|
+
} {
|
|
196
|
+
const aliases = this.getAliases();
|
|
197
|
+
const enabled = aliases.filter(a => a.enabled !== false);
|
|
198
|
+
const disabled = aliases.filter(a => a.enabled === false);
|
|
199
|
+
const directories = [...new Set(aliases.map(a => a.directory))];
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
total: aliases.length,
|
|
203
|
+
enabled: enabled.length,
|
|
204
|
+
disabled: disabled.length,
|
|
205
|
+
directories
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Checks if a given path is configured in the proxy (legacy method)
|
|
211
|
+
* @deprecated Use findMatchingAlias instead
|
|
26
212
|
* @param path
|
|
27
213
|
* @returns
|
|
28
214
|
*/
|
|
29
215
|
has(path: string): false | string {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return new RegExp(`^\/${dir.startsWith('/') ? dir.slice(1) : dir}/?.*`).test(path)
|
|
33
|
-
});
|
|
34
|
-
return !!found && found;
|
|
216
|
+
const alias = this.findMatchingAlias(path);
|
|
217
|
+
return alias ? alias.directory : false;
|
|
35
218
|
}
|
|
36
219
|
}
|
package/tsconfig.build.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2018",
|
|
4
|
-
"module": "esnext",
|
|
5
|
-
"jsx": "react-jsx",
|
|
6
|
-
"strict": true,
|
|
7
|
-
"resolveJsonModule": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"allowSyntheticDefaultImports": true,
|
|
10
|
-
"experimentalDecorators": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"baseUrl": ".",
|
|
13
|
-
"paths": {
|
|
14
|
-
"@adaas/a-server/constants/*": ["src/constants/*"],
|
|
15
|
-
"@adaas/a-server/defaults/*": ["src/defaults/*"],
|
|
16
|
-
"@adaas/a-server/decorators/*": ["src/decorators/*"],
|
|
17
|
-
"@adaas/a-server/helpers/*": ["src/helpers/*"],
|
|
18
|
-
"@adaas/a-server/examples/*": ["src/examples/*"],
|
|
19
|
-
"@adaas/a-server/entities/*": ["src/entities/*"],
|
|
20
|
-
"@adaas/a-server/channels/*": ["src/channels/*"],
|
|
21
|
-
"@adaas/a-server/context/*": ["src/context/*"],
|
|
22
|
-
"@adaas/a-server/components/*": ["src/components/*"],
|
|
23
|
-
"@adaas/a-server/containers/*": ["src/containers/*"]
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"include": ["src/**/*", "index.ts"],
|
|
27
|
-
"exclude": ["node_modules", "dist"]
|
|
28
|
-
}
|