spooder 6.2.3 → 6.2.5
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/README.md +26 -0
- package/bun.lock +3 -3
- package/package.json +1 -1
- package/src/api.ts +9 -2
- package/src/cli.ts +2 -1
package/README.md
CHANGED
|
@@ -302,6 +302,32 @@ This can be configured in `spooder` using the `instances` array, with each entry
|
|
|
302
302
|
|
|
303
303
|
Instances will be managed individually in the same manner that a single process would be, including auto-restarting and other functionality.
|
|
304
304
|
|
|
305
|
+
### Instance Environment
|
|
306
|
+
|
|
307
|
+
Each instance can define custom environment variables using the `env` property. These variables are merged with the parent process environment and passed to the spawned instance.
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
"spooder": {
|
|
311
|
+
"instances": [
|
|
312
|
+
{
|
|
313
|
+
"id": "foo",
|
|
314
|
+
"run": "bun run server.ts",
|
|
315
|
+
"env": { "ENVTEST": "foo" }
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
"id": "bar",
|
|
319
|
+
"run": "bun run server.ts",
|
|
320
|
+
"env": { "ENVTEST": "bar" }
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Environment variable precedence (highest to lowest):
|
|
327
|
+
1. `SPOODER_ENV` - always set by spooder (`dev` or `prod`)
|
|
328
|
+
2. Instance `env` - overrides parent environment
|
|
329
|
+
3. Parent process environment - inherited from spooder
|
|
330
|
+
|
|
305
331
|
### Instance Stagger
|
|
306
332
|
|
|
307
333
|
By default, instances are all launched instantly. This behavior can be configured with the `instance_stagger_interval` configuration property, which defines an interval between instance launches in milliseconds.
|
package/bun.lock
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
},
|
|
11
11
|
},
|
|
12
12
|
"packages": {
|
|
13
|
-
"@types/bun": ["@types/bun@1.3.
|
|
13
|
+
"@types/bun": ["@types/bun@1.3.8", "", { "dependencies": { "bun-types": "1.3.8" } }, "sha512-3LvWJ2q5GerAXYxO2mffLTqOzEu5qnhEAlh48Vnu8WQfnmSwbgagjGZV6BoHKJztENYEDn6QmVd949W4uESRJA=="],
|
|
14
14
|
|
|
15
|
-
"@types/node": ["@types/node@25.0
|
|
15
|
+
"@types/node": ["@types/node@25.2.0", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-DZ8VwRFUNzuqJ5khrvwMXHmvPe+zGayJhr2CDNiKB1WBE1ST8Djl00D0IC4vvNmHMdj6DlbYRIaFE7WHjlDl5w=="],
|
|
16
16
|
|
|
17
|
-
"bun-types": ["bun-types@1.3.
|
|
17
|
+
"bun-types": ["bun-types@1.3.8", "", { "dependencies": { "@types/node": "*" } }, "sha512-fL99nxdOWvV4LqjmC+8Q9kW3M4QTtTR1eePs94v5ctGqU8OeceWrSUaRw3JYb7tU3FkMIAjkueehrHPPPGKi5Q=="],
|
|
18
18
|
|
|
19
19
|
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
|
|
20
20
|
}
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -1904,10 +1904,17 @@ export function http_serve(port: number, hostname?: string) {
|
|
|
1904
1904
|
});
|
|
1905
1905
|
}
|
|
1906
1906
|
|
|
1907
|
+
const wrap_response = (result: ReturnType<typeof handler>) => {
|
|
1908
|
+
if (result !== null && typeof result === 'object' && !(result instanceof Response) && !(result instanceof Blob))
|
|
1909
|
+
return Response.json(result, { headers: { 'Cache-Control': 'no-store, no-cache, must-revalidate', 'Pragma': 'no-cache' } });
|
|
1910
|
+
|
|
1911
|
+
return result;
|
|
1912
|
+
};
|
|
1913
|
+
|
|
1907
1914
|
try {
|
|
1908
1915
|
// GET/HEAD requests don't have bodies, skip validation
|
|
1909
1916
|
if (req.method === 'GET' || req.method === 'HEAD')
|
|
1910
|
-
return handler(req, url, null);
|
|
1917
|
+
return wrap_response(await handler(req, url, null));
|
|
1911
1918
|
|
|
1912
1919
|
if (req.headers.get('Content-Type') !== 'application/json')
|
|
1913
1920
|
return 400; // Bad Request
|
|
@@ -1916,7 +1923,7 @@ export function http_serve(port: number, hostname?: string) {
|
|
|
1916
1923
|
if (json === null || typeof json !== 'object' || Array.isArray(json))
|
|
1917
1924
|
return 400; // Bad Request
|
|
1918
1925
|
|
|
1919
|
-
return handler(req, url, json as JsonObject);
|
|
1926
|
+
return wrap_response(await handler(req, url, json as JsonObject));
|
|
1920
1927
|
} catch (e) {
|
|
1921
1928
|
return 400; // Bad Request
|
|
1922
1929
|
}
|
package/src/cli.ts
CHANGED
|
@@ -10,6 +10,7 @@ type InstanceConfig = {
|
|
|
10
10
|
id: string;
|
|
11
11
|
run: string;
|
|
12
12
|
run_dev?: string;
|
|
13
|
+
env?: Record<string, string>;
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
type Instance = {
|
|
@@ -168,7 +169,7 @@ async function start_instance(instance: InstanceConfig, config: Config, update =
|
|
|
168
169
|
const run_command = is_dev_mode && instance.run_dev ? instance.run_dev : instance.run;
|
|
169
170
|
const proc = Bun.spawn(parse_command_line(run_command), {
|
|
170
171
|
cwd: process.cwd(),
|
|
171
|
-
env: { ...process.env, SPOODER_ENV: is_dev_mode ? 'dev' : 'prod' },
|
|
172
|
+
env: { ...process.env, ...instance.env, SPOODER_ENV: is_dev_mode ? 'dev' : 'prod' },
|
|
172
173
|
stdout: std_mode,
|
|
173
174
|
stderr: std_mode,
|
|
174
175
|
ipc: handle_ipc.bind({ instance_id: instance.id, config })
|