elit 3.1.6 → 3.1.7
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/build.d.mts +3 -1
- package/dist/cli.js +380 -218
- package/dist/database.d.mts +31 -0
- package/dist/database.d.ts +30 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +1197 -0
- package/dist/database.mjs +1170 -0
- package/dist/hmr.d.ts.map +1 -1
- package/dist/hmr.js +4 -5
- package/dist/hmr.mjs +4 -5
- package/dist/index.js +4 -5
- package/dist/index.mjs +4 -5
- package/dist/{server-D8ktU14v.d.mts → server-CRNme9Bc.d.mts} +14 -1
- package/dist/{server-CkRUWELa.d.ts → server-R_AfcxRw.d.ts} +14 -1
- package/dist/server.d.mts +3 -1
- package/dist/server.d.ts +10 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +367 -209
- package/dist/server.mjs +365 -209
- package/dist/types.d.mts +14 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -2
- package/src/cli.ts +2 -1
- package/src/database.ts +177 -0
- package/src/hmr.ts +7 -6
- package/src/server.ts +65 -25
- package/src/types.ts +7 -0
package/dist/types.d.mts
CHANGED
|
@@ -140,6 +140,14 @@ declare class WebSocket extends EventEmitter$1 {
|
|
|
140
140
|
get bufferedAmount(): number;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
interface DatabaseConfig {
|
|
144
|
+
dir?: string;
|
|
145
|
+
language?: 'ts' | 'js';
|
|
146
|
+
registerModules?: {
|
|
147
|
+
[key: string]: any;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
143
151
|
/**
|
|
144
152
|
* Development server with HMR support
|
|
145
153
|
* Cross-runtime transpilation support
|
|
@@ -328,6 +336,8 @@ interface DevServerOptions {
|
|
|
328
336
|
port?: number;
|
|
329
337
|
/** Host to bind to (default: 'localhost') */
|
|
330
338
|
host?: string;
|
|
339
|
+
/** Domain to map (e.g., 'idevcoder.com') - redirects domain traffic to this server's port */
|
|
340
|
+
domain?: string;
|
|
331
341
|
/** Root directory to serve files from */
|
|
332
342
|
root?: string;
|
|
333
343
|
/** Base path for the client application (e.g., '/app1', '/app2') */
|
|
@@ -358,6 +368,8 @@ interface DevServerOptions {
|
|
|
358
368
|
mode?: 'dev' | 'preview';
|
|
359
369
|
/** Environment variables to inject (prefix with VITE_ for client access) */
|
|
360
370
|
env?: Record<string, string>;
|
|
371
|
+
/** List of database directories to load */
|
|
372
|
+
database?: DatabaseConfig;
|
|
361
373
|
}
|
|
362
374
|
interface DevServer {
|
|
363
375
|
/** HTTP server instance */
|
|
@@ -433,6 +445,8 @@ interface PreviewOptions {
|
|
|
433
445
|
port?: number;
|
|
434
446
|
/** Host to bind to (default: 'localhost') */
|
|
435
447
|
host?: string;
|
|
448
|
+
/** Domain to map (e.g., 'idevcoder.com') - redirects domain traffic to this server's port */
|
|
449
|
+
domain?: string;
|
|
436
450
|
/** Root directory to serve files from (default: dist or build.outDir) */
|
|
437
451
|
root?: string;
|
|
438
452
|
/** Base path for the application (e.g., '/app') */
|
package/dist/types.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export type ElementFactory = {
|
|
|
57
57
|
};
|
|
58
58
|
import type { Server } from 'http';
|
|
59
59
|
import type { WebSocketServer } from 'ws';
|
|
60
|
+
import { DatabaseConfig } from './database';
|
|
60
61
|
export type Router = import('./server').ServerRouter;
|
|
61
62
|
export type StateManager = import('./server').StateManager;
|
|
62
63
|
export interface ClientConfig {
|
|
@@ -108,6 +109,8 @@ export interface DevServerOptions {
|
|
|
108
109
|
port?: number;
|
|
109
110
|
/** Host to bind to (default: 'localhost') */
|
|
110
111
|
host?: string;
|
|
112
|
+
/** Domain to map (e.g., 'idevcoder.com') - redirects domain traffic to this server's port */
|
|
113
|
+
domain?: string;
|
|
111
114
|
/** Root directory to serve files from */
|
|
112
115
|
root?: string;
|
|
113
116
|
/** Base path for the client application (e.g., '/app1', '/app2') */
|
|
@@ -138,6 +141,8 @@ export interface DevServerOptions {
|
|
|
138
141
|
mode?: 'dev' | 'preview';
|
|
139
142
|
/** Environment variables to inject (prefix with VITE_ for client access) */
|
|
140
143
|
env?: Record<string, string>;
|
|
144
|
+
/** List of database directories to load */
|
|
145
|
+
database?: DatabaseConfig;
|
|
141
146
|
}
|
|
142
147
|
export interface DevServer {
|
|
143
148
|
/** HTTP server instance */
|
|
@@ -213,6 +218,8 @@ export interface PreviewOptions {
|
|
|
213
218
|
port?: number;
|
|
214
219
|
/** Host to bind to (default: 'localhost') */
|
|
215
220
|
host?: string;
|
|
221
|
+
/** Domain to map (e.g., 'idevcoder.com') - redirects domain traffic to this server's port */
|
|
222
|
+
domain?: string;
|
|
216
223
|
/** Root directory to serve files from (default: dist or build.outDir) */
|
|
217
224
|
root?: string;
|
|
218
225
|
/** Base path for the application (e.g., '/app') */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,KAAK;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;CACtB;AAED,MAAM,MAAM,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AACzE,MAAM,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;AAE/B,MAAM,WAAW,KAAK;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC;IAC9C,uBAAuB,CAAC,EA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CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,WAAW;IACxB,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;CAChB;AAID,MAAM,WAAW,cAAc;IAC3B,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6FAA6F;IAC7F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,oCAAoC;IACpC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iDAAiD;IACjD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,qCAAqC;IACrC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,GAAG,CAAC,EAAE,MAAM,KAAK,GAAG,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,qDAAqD;IACrD,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;IACxB,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elit",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.7",
|
|
4
4
|
"description": "Optimized lightweight library for creating DOM elements with reactive state",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -100,6 +100,11 @@
|
|
|
100
100
|
"types": "./dist/runtime.d.ts",
|
|
101
101
|
"import": "./dist/runtime.mjs",
|
|
102
102
|
"require": "./dist/runtime.js"
|
|
103
|
+
},
|
|
104
|
+
"./database": {
|
|
105
|
+
"types": "./dist/database.d.ts",
|
|
106
|
+
"import": "./dist/database.mjs",
|
|
107
|
+
"require": "./dist/database.js"
|
|
103
108
|
}
|
|
104
109
|
},
|
|
105
110
|
"scripts": {
|
|
@@ -152,12 +157,13 @@
|
|
|
152
157
|
"open": "^11.0.0"
|
|
153
158
|
},
|
|
154
159
|
"devDependencies": {
|
|
160
|
+
"@types/bun": "^1.3.6",
|
|
155
161
|
"@types/express": "^5.0.6",
|
|
156
162
|
"@types/mime-types": "^2.1.4",
|
|
157
163
|
"@types/node": "^22.0.0",
|
|
158
164
|
"@types/ws": "^8.5.13",
|
|
159
|
-
"express": "^5.2.1",
|
|
160
165
|
"elysia": "^1.4.19",
|
|
166
|
+
"express": "^5.2.1",
|
|
161
167
|
"terser": "^5.44.1",
|
|
162
168
|
"tsup": "^8.0.0",
|
|
163
169
|
"typescript": "^5.3.0"
|
package/src/cli.ts
CHANGED
|
@@ -210,7 +210,8 @@ async function runPreview(args: string[]) {
|
|
|
210
210
|
port: mergedOptions.port || 4173,
|
|
211
211
|
host: mergedOptions.host || 'localhost',
|
|
212
212
|
open: mergedOptions.open ?? true,
|
|
213
|
-
logging: mergedOptions.logging ?? true
|
|
213
|
+
logging: mergedOptions.logging ?? true,
|
|
214
|
+
domain: mergedOptions.domain
|
|
214
215
|
};
|
|
215
216
|
|
|
216
217
|
// Support both single root and clients array
|
package/src/database.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import vm from "node:vm";
|
|
2
|
+
import { resolve } from "./path";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { serverDatabase } from "./server"
|
|
6
|
+
import * as esbuild from 'esbuild';
|
|
7
|
+
|
|
8
|
+
export interface DatabaseConfig {
|
|
9
|
+
dir?: string;
|
|
10
|
+
language?: 'ts' | 'js';
|
|
11
|
+
registerModules?: { [key: string]: any };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class Database {
|
|
15
|
+
private _ctx: vm.Context;
|
|
16
|
+
private _registerModules: { [key: string]: any };
|
|
17
|
+
private _config: DatabaseConfig = {
|
|
18
|
+
dir: resolve(process.cwd(), 'databases'),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
constructor(config: DatabaseConfig) {
|
|
22
|
+
this._config = { ...this._config, ...config };
|
|
23
|
+
this._registerModules = config.registerModules || {};
|
|
24
|
+
this._ctx = vm.createContext(this._registerModules);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
set config(config: DatabaseConfig) {
|
|
28
|
+
this._config = { ...this._config, ...config };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private register(context: { [key: string]: any }) {
|
|
32
|
+
this._registerModules = { ...this._registerModules, ...context };
|
|
33
|
+
// Register any custom modules or plugins here if needed
|
|
34
|
+
this._ctx = vm.createContext(this._registerModules);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
plugin(moduleName: string, moduleContent: any) {
|
|
38
|
+
this.register({ [moduleName]: moduleContent });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private resolvePath(fileList: any[], query: string) {
|
|
42
|
+
const aliases = { '@db': this._config.dir || resolve(process.cwd(), 'databases') };
|
|
43
|
+
|
|
44
|
+
let resolvedPath = query;
|
|
45
|
+
for (const [alias, target] of Object.entries(aliases)) {
|
|
46
|
+
if (resolvedPath.startsWith(alias + '/')) {
|
|
47
|
+
resolvedPath = resolvedPath.replace(alias, target);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Normalize path separators for cross-platform compatibility
|
|
53
|
+
resolvedPath = path.normalize(resolvedPath);
|
|
54
|
+
|
|
55
|
+
return fileList.find(file => {
|
|
56
|
+
const normalizedFile = path.normalize(file);
|
|
57
|
+
const fileWithoutExt = normalizedFile.replace(/\.[^/.]+$/, "");
|
|
58
|
+
return normalizedFile === resolvedPath ||
|
|
59
|
+
fileWithoutExt === resolvedPath ||
|
|
60
|
+
normalizedFile === resolvedPath + '.ts' ||
|
|
61
|
+
normalizedFile === resolvedPath + '.js';
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private async moduleLinker(specifier: any, referencingModule: any) {
|
|
66
|
+
// Try database files first
|
|
67
|
+
const dbFiles = fs.readdirSync(this._config.dir || resolve(process.cwd(), 'databases'))
|
|
68
|
+
.filter(f => f.endsWith(".ts"))
|
|
69
|
+
.map(f => path.join(this._config.dir || resolve(process.cwd(), 'databases'), f));
|
|
70
|
+
|
|
71
|
+
const dbResult = this.resolvePath(dbFiles, specifier);
|
|
72
|
+
if (dbResult) {
|
|
73
|
+
try {
|
|
74
|
+
const actualModule = await import(dbResult);
|
|
75
|
+
const exportNames = Object.keys(actualModule);
|
|
76
|
+
return new vm.SyntheticModule(
|
|
77
|
+
exportNames,
|
|
78
|
+
function () {
|
|
79
|
+
exportNames.forEach(key => {
|
|
80
|
+
this.setExport(key, actualModule[key]);
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
{ identifier: specifier, context: referencingModule.context }
|
|
84
|
+
);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error(`Failed to load database module ${specifier}:`, err);
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
throw new Error(`Module ${specifier} is not allowed or not found.`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
private async vmRun(code: string | Function, _options?: vm.RunningCodeOptions | string) {
|
|
96
|
+
const logs: any[] = [];
|
|
97
|
+
|
|
98
|
+
const customConsole = ['log', 'error', 'warn', 'info', 'debug', 'trace'].reduce((acc: any, type: any) => {
|
|
99
|
+
acc[type] = (...args: any[]) => logs.push({ type, args });
|
|
100
|
+
return acc;
|
|
101
|
+
}, {});
|
|
102
|
+
|
|
103
|
+
this.register({
|
|
104
|
+
console: customConsole
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
let stringCode: string;
|
|
108
|
+
if (typeof code === 'function') {
|
|
109
|
+
const funcStr = code.toString();
|
|
110
|
+
// ตัด arrow function หรือ function keyword และ opening brace ออก
|
|
111
|
+
const arrowMatch = funcStr.match(/^[\s]*\(?\s*\)?\s*=>\s*{?/);
|
|
112
|
+
const functionMatch = funcStr.match(/^[\s]*function\s*\(?[\w\s]*\)?\s*{/);
|
|
113
|
+
const match = arrowMatch || functionMatch;
|
|
114
|
+
const start = match ? match[0].length : 0;
|
|
115
|
+
const end = funcStr.lastIndexOf('}');
|
|
116
|
+
stringCode = funcStr.substring(start, end);
|
|
117
|
+
// Trim leading newline, spaces, and trailing
|
|
118
|
+
stringCode = stringCode.replace(/^[\s\r\n]+/, '').replace(/[\s\r\n]+$/, '');
|
|
119
|
+
|
|
120
|
+
// Transform import(aa).from("module") to import aa from "module"
|
|
121
|
+
stringCode = stringCode.replace(
|
|
122
|
+
/import\s*\(\s*([^)]+?)\s*\)\s*\.from\s*\(\s*(['"])([^'"]+)\2\s*\)/g,
|
|
123
|
+
(_, importArg, quote, modulePath) => {
|
|
124
|
+
// Check if importArg is wrapped in braces (destructuring)
|
|
125
|
+
const trimmed = importArg.trim();
|
|
126
|
+
if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
127
|
+
// Destructuring: import({bb}) -> import { bb }
|
|
128
|
+
const inner = trimmed.slice(1, -1).trim();
|
|
129
|
+
return `import { ${inner} } from ${quote}${modulePath}${quote}`;
|
|
130
|
+
} else {
|
|
131
|
+
// Default: import(aa) -> import aa
|
|
132
|
+
return `import ${trimmed} from ${quote}${modulePath}${quote}`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// Trim leading whitespace from each line
|
|
138
|
+
stringCode = stringCode.split('\n').map(line => line.trim()).join('\n').trim();
|
|
139
|
+
} else {
|
|
140
|
+
stringCode = code;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Transpile using esbuild
|
|
144
|
+
const result = await esbuild.build({
|
|
145
|
+
stdin: {
|
|
146
|
+
contents: stringCode,
|
|
147
|
+
loader: this._config.language || 'ts',
|
|
148
|
+
},
|
|
149
|
+
format: 'esm',
|
|
150
|
+
target: 'es2020',
|
|
151
|
+
write: false,
|
|
152
|
+
bundle: false,
|
|
153
|
+
sourcemap: false,
|
|
154
|
+
});
|
|
155
|
+
const js = result.outputFiles[0].text;
|
|
156
|
+
|
|
157
|
+
const mod = new vm.SourceTextModule(js, { context: this._ctx, identifier: path.join(this._config.dir || resolve(process.cwd(), 'databases'), 'virtual-entry.js') });
|
|
158
|
+
await mod.link(this.moduleLinker.bind(this));
|
|
159
|
+
await mod.evaluate();
|
|
160
|
+
return {
|
|
161
|
+
namespace: mod.namespace,
|
|
162
|
+
logs: logs
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Execute database code and return results
|
|
168
|
+
*/
|
|
169
|
+
async execute(code: string | Function, options?: vm.RunningCodeOptions | string) {
|
|
170
|
+
return await this.vmRun(code, options);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export const database = serverDatabase.database;
|
|
176
|
+
|
|
177
|
+
export default database;
|
package/src/hmr.ts
CHANGED
|
@@ -66,8 +66,8 @@ class ElitHMR implements HMRClient {
|
|
|
66
66
|
|
|
67
67
|
this.ws.onclose = () => {
|
|
68
68
|
this.enabled = false;
|
|
69
|
-
console.log('[Elit HMR] Disconnected -
|
|
70
|
-
|
|
69
|
+
console.log('[Elit HMR] Disconnected - HMR disabled until manual refresh');
|
|
70
|
+
// Don't auto-reload, let user decide when to refresh
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
this.ws.onerror = (error) => {
|
|
@@ -93,17 +93,18 @@ class ElitHMR implements HMRClient {
|
|
|
93
93
|
this.disposeCallbacks.forEach(cb => cb());
|
|
94
94
|
this.disposeCallbacks = [];
|
|
95
95
|
|
|
96
|
-
// Run accept callbacks or reload
|
|
96
|
+
// Run accept callbacks or log (don't auto-reload)
|
|
97
97
|
if (this.acceptCallbacks.length > 0) {
|
|
98
98
|
this.acceptCallbacks.forEach(cb => cb());
|
|
99
|
+
console.log('[Elit HMR] Update accepted via callback');
|
|
99
100
|
} else {
|
|
100
|
-
|
|
101
|
+
console.log('[Elit HMR] Update detected - manually refresh to see changes');
|
|
101
102
|
}
|
|
102
103
|
break;
|
|
103
104
|
|
|
104
105
|
case 'reload':
|
|
105
|
-
console.log('[Elit HMR] Full reload requested');
|
|
106
|
-
|
|
106
|
+
console.log('[Elit HMR] Full reload requested - manually refresh to see changes');
|
|
107
|
+
// Don't auto-reload
|
|
107
108
|
break;
|
|
108
109
|
|
|
109
110
|
case 'error':
|
package/src/server.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { lookup } from './mime-types';
|
|
|
16
16
|
import { isBun, isDeno } from './runtime';
|
|
17
17
|
import type { DevServerOptions, DevServer, HMRMessage, Child, VNode, ProxyConfig } from './types';
|
|
18
18
|
import { dom } from './dom';
|
|
19
|
+
import { Database, DatabaseConfig } from './database';
|
|
19
20
|
|
|
20
21
|
// ===== Router =====
|
|
21
22
|
|
|
@@ -46,6 +47,25 @@ interface ServerRoute {
|
|
|
46
47
|
middlewares: Middleware[];
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
class ServerDatabase {
|
|
51
|
+
private _db: Database | null = null;
|
|
52
|
+
|
|
53
|
+
constructor() {
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async initialize(config: DatabaseConfig) {
|
|
58
|
+
this._db = new Database(config);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
database(){
|
|
62
|
+
return this._db;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const serverDatabase = new ServerDatabase();
|
|
67
|
+
|
|
68
|
+
export const database = serverDatabase.database;
|
|
49
69
|
export class ServerRouter {
|
|
50
70
|
private routes: ServerRoute[] = [];
|
|
51
71
|
private middlewares: Middleware[] = [];
|
|
@@ -173,10 +193,10 @@ export class ServerRouter {
|
|
|
173
193
|
try {
|
|
174
194
|
const text = await (req as any).text();
|
|
175
195
|
if (!text) return {};
|
|
176
|
-
|
|
196
|
+
|
|
177
197
|
const contentType = req.headers['content-type'];
|
|
178
198
|
const ct = (Array.isArray(contentType) ? contentType[0] : (contentType || '')).toLowerCase();
|
|
179
|
-
|
|
199
|
+
|
|
180
200
|
// Parse JSON (either by content-type or if it looks like JSON)
|
|
181
201
|
if (ct.includes('application/json') || ct.includes('json') || text.trim().startsWith('{') || text.trim().startsWith('[')) {
|
|
182
202
|
try {
|
|
@@ -185,12 +205,12 @@ export class ServerRouter {
|
|
|
185
205
|
return text;
|
|
186
206
|
}
|
|
187
207
|
}
|
|
188
|
-
|
|
208
|
+
|
|
189
209
|
// Parse URL-encoded
|
|
190
210
|
if (ct.includes('application/x-www-form-urlencoded') || ct.includes('urlencoded')) {
|
|
191
211
|
return Object.fromEntries(new URLSearchParams(text));
|
|
192
212
|
}
|
|
193
|
-
|
|
213
|
+
|
|
194
214
|
// Return raw text
|
|
195
215
|
return text;
|
|
196
216
|
} catch (e) {
|
|
@@ -203,28 +223,28 @@ export class ServerRouter {
|
|
|
203
223
|
return new Promise((resolve, reject) => {
|
|
204
224
|
const contentLengthHeader = req.headers['content-length'];
|
|
205
225
|
const contentLength = parseInt(Array.isArray(contentLengthHeader) ? contentLengthHeader[0] : (contentLengthHeader || '0'), 10);
|
|
206
|
-
|
|
226
|
+
|
|
207
227
|
if (contentLength === 0) {
|
|
208
228
|
resolve({});
|
|
209
229
|
return;
|
|
210
230
|
}
|
|
211
231
|
|
|
212
232
|
const chunks: Buffer[] = [];
|
|
213
|
-
|
|
233
|
+
|
|
214
234
|
req.on('data', chunk => {
|
|
215
235
|
chunks.push(Buffer.from(chunk));
|
|
216
236
|
});
|
|
217
|
-
|
|
237
|
+
|
|
218
238
|
req.on('end', () => {
|
|
219
239
|
const body = Buffer.concat(chunks).toString();
|
|
220
240
|
try {
|
|
221
241
|
const ct = req.headers['content-type'] || '';
|
|
222
242
|
resolve(ct.includes('json') ? (body ? JSON.parse(body) : {}) : ct.includes('urlencoded') ? Object.fromEntries(new URLSearchParams(body)) : body);
|
|
223
|
-
} catch (e) {
|
|
224
|
-
reject(e);
|
|
243
|
+
} catch (e) {
|
|
244
|
+
reject(e);
|
|
225
245
|
}
|
|
226
246
|
});
|
|
227
|
-
|
|
247
|
+
|
|
228
248
|
req.on('error', reject);
|
|
229
249
|
});
|
|
230
250
|
}
|
|
@@ -240,25 +260,25 @@ export class ServerRouter {
|
|
|
240
260
|
|
|
241
261
|
let body: any = {};
|
|
242
262
|
if (['POST', 'PUT', 'PATCH'].includes(method)) {
|
|
243
|
-
try {
|
|
263
|
+
try {
|
|
244
264
|
body = await this.parseBody(req);
|
|
245
265
|
}
|
|
246
|
-
catch (e) {
|
|
247
|
-
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
248
|
-
res.end('{"error":"Invalid request body"}');
|
|
249
|
-
return true;
|
|
266
|
+
catch (e) {
|
|
267
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
268
|
+
res.end('{"error":"Invalid request body"}');
|
|
269
|
+
return true;
|
|
250
270
|
}
|
|
251
271
|
}
|
|
252
272
|
|
|
253
273
|
// Add Express-like response helpers to context
|
|
254
|
-
const ctx: ServerRouteContext = {
|
|
255
|
-
req,
|
|
256
|
-
res,
|
|
257
|
-
params,
|
|
258
|
-
query: this.parseQuery(url),
|
|
259
|
-
body,
|
|
274
|
+
const ctx: ServerRouteContext = {
|
|
275
|
+
req,
|
|
276
|
+
res,
|
|
277
|
+
params,
|
|
278
|
+
query: this.parseQuery(url),
|
|
279
|
+
body,
|
|
260
280
|
headers: req.headers as any,
|
|
261
|
-
send: (data: any) => {
|
|
281
|
+
send: (data: any) => {
|
|
262
282
|
if (!res.headersSent) {
|
|
263
283
|
if (typeof data === 'object') {
|
|
264
284
|
res.setHeader('Content-Type', 'application/json');
|
|
@@ -300,8 +320,8 @@ export class ServerRouter {
|
|
|
300
320
|
await mw(ctx, next);
|
|
301
321
|
};
|
|
302
322
|
|
|
303
|
-
try {
|
|
304
|
-
await next();
|
|
323
|
+
try {
|
|
324
|
+
await next();
|
|
305
325
|
}
|
|
306
326
|
catch (e) {
|
|
307
327
|
console.error('[ServerRouter] Route error:', e);
|
|
@@ -1074,7 +1094,7 @@ export class StateManager {
|
|
|
1074
1094
|
|
|
1075
1095
|
// ===== Development Server =====
|
|
1076
1096
|
|
|
1077
|
-
const defaultOptions: Omit<Required<DevServerOptions>, 'api' | 'clients' | 'root' | 'basePath' | 'ssr' | 'proxy' | 'index' | 'env'> = {
|
|
1097
|
+
const defaultOptions: Omit<Required<DevServerOptions>, 'api' | 'clients' | 'root' | 'basePath' | 'ssr' | 'proxy' | 'index' | 'env' | 'domain' | 'database'> = {
|
|
1078
1098
|
port: 3000,
|
|
1079
1099
|
host: 'localhost',
|
|
1080
1100
|
https: false,
|
|
@@ -1106,6 +1126,13 @@ export function createDevServer(options: DevServerOptions): DevServer {
|
|
|
1106
1126
|
clearImportMapCache();
|
|
1107
1127
|
}
|
|
1108
1128
|
|
|
1129
|
+
// Initialize database connections if provided
|
|
1130
|
+
if (config.database) {
|
|
1131
|
+
serverDatabase.initialize(config.database);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
|
|
1109
1136
|
// Normalize clients configuration - support both new API (clients array) and legacy API (root/basePath)
|
|
1110
1137
|
const clientsToNormalize = config.clients?.length ? config.clients : config.root ? [{ root: config.root, basePath: config.basePath || '', index: config.index, ssr: config.ssr, api: config.api, proxy: config.proxy, mode: config.mode }] : null;
|
|
1111
1138
|
if (!clientsToNormalize) throw new Error('DevServerOptions must include either "clients" array or "root" directory');
|
|
@@ -1146,6 +1173,19 @@ export function createDevServer(options: DevServerOptions): DevServer {
|
|
|
1146
1173
|
// HTTP Server
|
|
1147
1174
|
const server = createServer(async (req: IncomingMessage, res: ServerResponse) => {
|
|
1148
1175
|
const originalUrl = req.url || '/';
|
|
1176
|
+
const hostHeader = req.headers.host;
|
|
1177
|
+
const hostName = hostHeader ? (Array.isArray(hostHeader) ? hostHeader[0] : hostHeader).split(':')[0] : '';
|
|
1178
|
+
|
|
1179
|
+
// Handle domain mapping: redirect localhost:port to configured domain
|
|
1180
|
+
if (config.domain && hostName === (config.host || 'localhost')) {
|
|
1181
|
+
const redirectUrl = `http://${config.domain}${originalUrl}`;
|
|
1182
|
+
if (config.logging) {
|
|
1183
|
+
console.log(`[Domain Map] ${hostName}:${config.port}${originalUrl} -> ${redirectUrl}`);
|
|
1184
|
+
}
|
|
1185
|
+
res.writeHead(302, { Location: redirectUrl });
|
|
1186
|
+
res.end();
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1149
1189
|
|
|
1150
1190
|
// Find matching client based on basePath
|
|
1151
1191
|
const matchedClient = normalizedClients.find(c => c.basePath && originalUrl.startsWith(c.basePath)) || normalizedClients.find(c => !c.basePath);
|
package/src/types.ts
CHANGED
|
@@ -72,6 +72,7 @@ export type ElementFactory = {
|
|
|
72
72
|
|
|
73
73
|
import type { Server } from 'http';
|
|
74
74
|
import type { WebSocketServer } from 'ws';
|
|
75
|
+
import { DatabaseConfig } from './database';
|
|
75
76
|
|
|
76
77
|
// Forward declarations to avoid circular dependency
|
|
77
78
|
export type Router = import('./server').ServerRouter;
|
|
@@ -129,6 +130,8 @@ export interface DevServerOptions {
|
|
|
129
130
|
port?: number;
|
|
130
131
|
/** Host to bind to (default: 'localhost') */
|
|
131
132
|
host?: string;
|
|
133
|
+
/** Domain to map (e.g., 'idevcoder.com') - redirects domain traffic to this server's port */
|
|
134
|
+
domain?: string;
|
|
132
135
|
/** Root directory to serve files from */
|
|
133
136
|
root?: string;
|
|
134
137
|
/** Base path for the client application (e.g., '/app1', '/app2') */
|
|
@@ -159,6 +162,8 @@ export interface DevServerOptions {
|
|
|
159
162
|
mode?: 'dev' | 'preview';
|
|
160
163
|
/** Environment variables to inject (prefix with VITE_ for client access) */
|
|
161
164
|
env?: Record<string, string>;
|
|
165
|
+
/** List of database directories to load */
|
|
166
|
+
database?: DatabaseConfig;
|
|
162
167
|
}
|
|
163
168
|
|
|
164
169
|
export interface DevServer {
|
|
@@ -239,6 +244,8 @@ export interface PreviewOptions {
|
|
|
239
244
|
port?: number;
|
|
240
245
|
/** Host to bind to (default: 'localhost') */
|
|
241
246
|
host?: string;
|
|
247
|
+
/** Domain to map (e.g., 'idevcoder.com') - redirects domain traffic to this server's port */
|
|
248
|
+
domain?: string;
|
|
242
249
|
/** Root directory to serve files from (default: dist or build.outDir) */
|
|
243
250
|
root?: string;
|
|
244
251
|
/** Base path for the application (e.g., '/app') */
|