threadforge 0.1.1 → 0.2.2
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 +69 -42
- package/bin/forge.js +2 -1058
- package/bin/host-commands.d.ts +2 -0
- package/bin/host-commands.d.ts.map +1 -0
- package/bin/host-commands.js +7 -8
- package/bin/platform-commands.d.ts +2 -0
- package/bin/platform-commands.d.ts.map +1 -0
- package/bin/platform-commands.js +118 -36
- package/dist/cli/base-command.d.ts +12 -0
- package/dist/cli/base-command.d.ts.map +1 -0
- package/dist/cli/base-command.js +25 -0
- package/dist/cli/base-command.js.map +1 -0
- package/dist/cli/commands/build.d.ts +10 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +110 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/deploy.d.ts +12 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -0
- package/dist/cli/commands/deploy.js +143 -0
- package/dist/cli/commands/deploy.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +10 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +138 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +10 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +76 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/host.d.ts +8 -0
- package/dist/cli/commands/host.d.ts.map +1 -0
- package/dist/cli/commands/host.js +20 -0
- package/dist/cli/commands/host.js.map +1 -0
- package/dist/cli/commands/init.d.ts +16 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +246 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/platform.d.ts +8 -0
- package/dist/cli/commands/platform.d.ts.map +1 -0
- package/dist/cli/commands/platform.js +20 -0
- package/dist/cli/commands/platform.js.map +1 -0
- package/dist/cli/commands/restart.d.ts +8 -0
- package/dist/cli/commands/restart.d.ts.map +1 -0
- package/dist/cli/commands/restart.js +13 -0
- package/dist/cli/commands/restart.js.map +1 -0
- package/dist/cli/commands/scaffold/frontend.d.ts +10 -0
- package/dist/cli/commands/scaffold/frontend.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/frontend.js +130 -0
- package/dist/cli/commands/scaffold/frontend.js.map +1 -0
- package/dist/cli/commands/scaffold/react.d.ts +7 -0
- package/dist/cli/commands/scaffold/react.d.ts.map +1 -0
- package/dist/cli/commands/scaffold/react.js +12 -0
- package/dist/cli/commands/scaffold/react.js.map +1 -0
- package/dist/cli/commands/scale.d.ts +8 -0
- package/dist/cli/commands/scale.d.ts.map +1 -0
- package/dist/cli/commands/scale.js +13 -0
- package/dist/cli/commands/scale.js.map +1 -0
- package/dist/cli/commands/start.d.ts +10 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +71 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/status.d.ts +11 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +60 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/stop.d.ts +10 -0
- package/dist/cli/commands/stop.d.ts.map +1 -0
- package/dist/cli/commands/stop.js +89 -0
- package/dist/cli/commands/stop.js.map +1 -0
- package/dist/cli/util/config-discovery.d.ts +8 -0
- package/dist/cli/util/config-discovery.d.ts.map +1 -0
- package/dist/cli/util/config-discovery.js +70 -0
- package/dist/cli/util/config-discovery.js.map +1 -0
- package/dist/cli/util/config-patcher.d.ts +17 -0
- package/dist/cli/util/config-patcher.d.ts.map +1 -0
- package/dist/cli/util/config-patcher.js +439 -0
- package/dist/cli/util/config-patcher.js.map +1 -0
- package/dist/cli/util/frontend-dev.d.ts +8 -0
- package/dist/cli/util/frontend-dev.d.ts.map +1 -0
- package/dist/cli/util/frontend-dev.js +117 -0
- package/dist/cli/util/frontend-dev.js.map +1 -0
- package/dist/cli/util/process.d.ts +5 -0
- package/dist/cli/util/process.d.ts.map +1 -0
- package/dist/cli/util/process.js +17 -0
- package/dist/cli/util/process.js.map +1 -0
- package/dist/cli/util/templates.d.ts +10 -0
- package/dist/cli/util/templates.d.ts.map +1 -0
- package/dist/cli/util/templates.js +157 -0
- package/dist/cli/util/templates.js.map +1 -0
- package/dist/core/AlertSink.d.ts +83 -0
- package/dist/core/AlertSink.d.ts.map +1 -0
- package/dist/core/AlertSink.js +126 -0
- package/dist/core/AlertSink.js.map +1 -0
- package/dist/core/DirectMessageBus.d.ts +88 -0
- package/dist/core/DirectMessageBus.d.ts.map +1 -0
- package/dist/core/DirectMessageBus.js +352 -0
- package/dist/core/DirectMessageBus.js.map +1 -0
- package/dist/core/EndpointResolver.d.ts +111 -0
- package/dist/core/EndpointResolver.d.ts.map +1 -0
- package/dist/core/EndpointResolver.js +336 -0
- package/dist/core/EndpointResolver.js.map +1 -0
- package/dist/core/ForgeContext.d.ts +221 -0
- package/dist/core/ForgeContext.d.ts.map +1 -0
- package/dist/core/ForgeContext.js +1169 -0
- package/dist/core/ForgeContext.js.map +1 -0
- package/dist/core/ForgeEndpoints.d.ts +71 -0
- package/dist/core/ForgeEndpoints.d.ts.map +1 -0
- package/dist/core/ForgeEndpoints.js +442 -0
- package/dist/core/ForgeEndpoints.js.map +1 -0
- package/dist/core/ForgeHost.d.ts +82 -0
- package/dist/core/ForgeHost.d.ts.map +1 -0
- package/dist/core/ForgeHost.js +107 -0
- package/dist/core/ForgeHost.js.map +1 -0
- package/dist/core/ForgePlatform.d.ts +96 -0
- package/dist/core/ForgePlatform.d.ts.map +1 -0
- package/dist/core/ForgePlatform.js +136 -0
- package/dist/core/ForgePlatform.js.map +1 -0
- package/dist/core/ForgeWebSocket.d.ts +56 -0
- package/dist/core/ForgeWebSocket.d.ts.map +1 -0
- package/dist/core/ForgeWebSocket.js +415 -0
- package/dist/core/ForgeWebSocket.js.map +1 -0
- package/dist/core/Ingress.d.ts +329 -0
- package/dist/core/Ingress.d.ts.map +1 -0
- package/dist/core/Ingress.js +694 -0
- package/dist/core/Ingress.js.map +1 -0
- package/dist/core/Interceptors.d.ts +134 -0
- package/dist/core/Interceptors.d.ts.map +1 -0
- package/dist/core/Interceptors.js +416 -0
- package/dist/core/Interceptors.js.map +1 -0
- package/dist/core/Logger.d.ts +20 -0
- package/dist/core/Logger.d.ts.map +1 -0
- package/dist/core/Logger.js +77 -0
- package/dist/core/Logger.js.map +1 -0
- package/dist/core/MessageBus.d.ts +15 -0
- package/dist/core/MessageBus.d.ts.map +1 -0
- package/dist/core/MessageBus.js +18 -0
- package/dist/core/MessageBus.js.map +1 -0
- package/dist/core/Prometheus.d.ts +80 -0
- package/dist/core/Prometheus.d.ts.map +1 -0
- package/dist/core/Prometheus.js +332 -0
- package/dist/core/Prometheus.js.map +1 -0
- package/dist/core/RequestContext.d.ts +214 -0
- package/dist/core/RequestContext.d.ts.map +1 -0
- package/dist/core/RequestContext.js +556 -0
- package/dist/core/RequestContext.js.map +1 -0
- package/dist/core/Router.d.ts +45 -0
- package/dist/core/Router.d.ts.map +1 -0
- package/dist/core/Router.js +285 -0
- package/dist/core/Router.js.map +1 -0
- package/dist/core/RoutingStrategy.d.ts +116 -0
- package/dist/core/RoutingStrategy.d.ts.map +1 -0
- package/dist/core/RoutingStrategy.js +306 -0
- package/dist/core/RoutingStrategy.js.map +1 -0
- package/dist/core/RpcConfig.d.ts +72 -0
- package/dist/core/RpcConfig.d.ts.map +1 -0
- package/dist/core/RpcConfig.js +127 -0
- package/dist/core/RpcConfig.js.map +1 -0
- package/dist/core/SignatureCache.d.ts +81 -0
- package/dist/core/SignatureCache.d.ts.map +1 -0
- package/dist/core/SignatureCache.js +172 -0
- package/dist/core/SignatureCache.js.map +1 -0
- package/dist/core/StaticFileServer.d.ts +34 -0
- package/dist/core/StaticFileServer.d.ts.map +1 -0
- package/dist/core/StaticFileServer.js +497 -0
- package/dist/core/StaticFileServer.js.map +1 -0
- package/dist/core/Supervisor.d.ts +198 -0
- package/dist/core/Supervisor.d.ts.map +1 -0
- package/dist/core/Supervisor.js +1418 -0
- package/dist/core/Supervisor.js.map +1 -0
- package/dist/core/ThreadAllocator.d.ts +52 -0
- package/dist/core/ThreadAllocator.d.ts.map +1 -0
- package/dist/core/ThreadAllocator.js +174 -0
- package/dist/core/ThreadAllocator.js.map +1 -0
- package/dist/core/WorkerChannelManager.d.ts +130 -0
- package/dist/core/WorkerChannelManager.d.ts.map +1 -0
- package/dist/core/WorkerChannelManager.js +956 -0
- package/dist/core/WorkerChannelManager.js.map +1 -0
- package/dist/core/config-enums.d.ts +41 -0
- package/dist/core/config-enums.d.ts.map +1 -0
- package/dist/core/config-enums.js +59 -0
- package/dist/core/config-enums.js.map +1 -0
- package/dist/core/config.d.ts +159 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +694 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/host-config.d.ts +146 -0
- package/dist/core/host-config.d.ts.map +1 -0
- package/dist/core/host-config.js +312 -0
- package/dist/core/host-config.js.map +1 -0
- package/dist/core/ipc-errors.d.ts +27 -0
- package/dist/core/ipc-errors.d.ts.map +1 -0
- package/dist/core/ipc-errors.js +36 -0
- package/dist/core/ipc-errors.js.map +1 -0
- package/dist/core/network-utils.d.ts +35 -0
- package/dist/core/network-utils.d.ts.map +1 -0
- package/dist/core/network-utils.js +145 -0
- package/dist/core/network-utils.js.map +1 -0
- package/dist/core/platform-config.d.ts +142 -0
- package/dist/core/platform-config.d.ts.map +1 -0
- package/dist/core/platform-config.js +299 -0
- package/dist/core/platform-config.js.map +1 -0
- package/dist/decorators/ServiceProxy.d.ts +175 -0
- package/dist/decorators/ServiceProxy.d.ts.map +1 -0
- package/dist/decorators/ServiceProxy.js +969 -0
- package/dist/decorators/ServiceProxy.js.map +1 -0
- package/dist/decorators/index.d.ts +146 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +545 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/deploy/NginxGenerator.d.ts +165 -0
- package/dist/deploy/NginxGenerator.d.ts.map +1 -0
- package/dist/deploy/NginxGenerator.js +781 -0
- package/dist/deploy/NginxGenerator.js.map +1 -0
- package/dist/deploy/PlatformManifestGenerator.d.ts +43 -0
- package/dist/deploy/PlatformManifestGenerator.d.ts.map +1 -0
- package/dist/deploy/PlatformManifestGenerator.js +80 -0
- package/dist/deploy/PlatformManifestGenerator.js.map +1 -0
- package/dist/deploy/RouteManifestGenerator.d.ts +42 -0
- package/dist/deploy/RouteManifestGenerator.d.ts.map +1 -0
- package/dist/deploy/RouteManifestGenerator.js +105 -0
- package/dist/deploy/RouteManifestGenerator.js.map +1 -0
- package/dist/deploy/index.d.ts +210 -0
- package/dist/deploy/index.d.ts.map +1 -0
- package/dist/deploy/index.js +918 -0
- package/dist/deploy/index.js.map +1 -0
- package/dist/frontend/FrontendDevLifecycle.d.ts +26 -0
- package/dist/frontend/FrontendDevLifecycle.d.ts.map +1 -0
- package/dist/frontend/FrontendDevLifecycle.js +60 -0
- package/dist/frontend/FrontendDevLifecycle.js.map +1 -0
- package/dist/frontend/FrontendPluginOrchestrator.d.ts +64 -0
- package/dist/frontend/FrontendPluginOrchestrator.d.ts.map +1 -0
- package/dist/frontend/FrontendPluginOrchestrator.js +167 -0
- package/dist/frontend/FrontendPluginOrchestrator.js.map +1 -0
- package/dist/frontend/SiteResolver.d.ts +33 -0
- package/dist/frontend/SiteResolver.d.ts.map +1 -0
- package/dist/frontend/SiteResolver.js +53 -0
- package/dist/frontend/SiteResolver.js.map +1 -0
- package/dist/frontend/StaticMountRegistry.d.ts +36 -0
- package/dist/frontend/StaticMountRegistry.d.ts.map +1 -0
- package/dist/frontend/StaticMountRegistry.js +94 -0
- package/dist/frontend/StaticMountRegistry.js.map +1 -0
- package/dist/frontend/index.d.ts +7 -0
- package/dist/frontend/index.d.ts.map +1 -0
- package/{src → dist}/frontend/index.js +4 -2
- package/dist/frontend/index.js.map +1 -0
- package/dist/frontend/pathUtils.d.ts +8 -0
- package/dist/frontend/pathUtils.d.ts.map +1 -0
- package/dist/frontend/pathUtils.js +17 -0
- package/dist/frontend/pathUtils.js.map +1 -0
- package/dist/frontend/plugins/index.d.ts +2 -0
- package/dist/frontend/plugins/index.d.ts.map +1 -0
- package/{src → dist}/frontend/plugins/index.js +1 -1
- package/dist/frontend/plugins/index.js.map +1 -0
- package/dist/frontend/plugins/viteFrontend.d.ts +51 -0
- package/dist/frontend/plugins/viteFrontend.d.ts.map +1 -0
- package/dist/frontend/plugins/viteFrontend.js +134 -0
- package/dist/frontend/plugins/viteFrontend.js.map +1 -0
- package/dist/frontend/types.d.ts +25 -0
- package/dist/frontend/types.d.ts.map +1 -0
- package/dist/frontend/types.js +2 -0
- package/dist/frontend/types.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/internals.d.ts +21 -0
- package/dist/internals.d.ts.map +1 -0
- package/{src → dist}/internals.js +12 -14
- package/dist/internals.js.map +1 -0
- package/dist/plugins/PluginManager.d.ts +209 -0
- package/dist/plugins/PluginManager.d.ts.map +1 -0
- package/dist/plugins/PluginManager.js +365 -0
- package/dist/plugins/PluginManager.js.map +1 -0
- package/dist/plugins/ScopedPostgres.d.ts +78 -0
- package/dist/plugins/ScopedPostgres.d.ts.map +1 -0
- package/dist/plugins/ScopedPostgres.js +190 -0
- package/dist/plugins/ScopedPostgres.js.map +1 -0
- package/dist/plugins/ScopedRedis.d.ts +88 -0
- package/dist/plugins/ScopedRedis.d.ts.map +1 -0
- package/dist/plugins/ScopedRedis.js +169 -0
- package/dist/plugins/ScopedRedis.js.map +1 -0
- package/dist/plugins/index.d.ts +289 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +1942 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/types.d.ts +59 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +2 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/registry/ServiceRegistry.d.ts +305 -0
- package/dist/registry/ServiceRegistry.d.ts.map +1 -0
- package/dist/registry/ServiceRegistry.js +735 -0
- package/dist/registry/ServiceRegistry.js.map +1 -0
- package/dist/scaling/ScaleAdvisor.d.ts +214 -0
- package/dist/scaling/ScaleAdvisor.d.ts.map +1 -0
- package/dist/scaling/ScaleAdvisor.js +526 -0
- package/dist/scaling/ScaleAdvisor.js.map +1 -0
- package/dist/services/Service.d.ts +164 -0
- package/dist/services/Service.d.ts.map +1 -0
- package/dist/services/Service.js +106 -0
- package/dist/services/Service.js.map +1 -0
- package/dist/services/worker-bootstrap.d.ts +15 -0
- package/dist/services/worker-bootstrap.d.ts.map +1 -0
- package/dist/services/worker-bootstrap.js +744 -0
- package/dist/services/worker-bootstrap.js.map +1 -0
- package/dist/templates/auth-service.d.ts +42 -0
- package/dist/templates/auth-service.d.ts.map +1 -0
- package/dist/templates/auth-service.js +54 -0
- package/dist/templates/auth-service.js.map +1 -0
- package/dist/templates/identity-service.d.ts +50 -0
- package/dist/templates/identity-service.d.ts.map +1 -0
- package/dist/templates/identity-service.js +62 -0
- package/dist/templates/identity-service.js.map +1 -0
- package/dist/types/contract.d.ts +120 -0
- package/dist/types/contract.d.ts.map +1 -0
- package/dist/types/contract.js +69 -0
- package/dist/types/contract.js.map +1 -0
- package/package.json +79 -20
- package/src/core/DirectMessageBus.js +0 -364
- package/src/core/EndpointResolver.js +0 -259
- package/src/core/ForgeContext.js +0 -2236
- package/src/core/ForgeHost.js +0 -122
- package/src/core/ForgePlatform.js +0 -145
- package/src/core/Ingress.js +0 -768
- package/src/core/Interceptors.js +0 -420
- package/src/core/MessageBus.js +0 -321
- package/src/core/Prometheus.js +0 -305
- package/src/core/RequestContext.js +0 -413
- package/src/core/RoutingStrategy.js +0 -330
- package/src/core/Supervisor.js +0 -1349
- package/src/core/ThreadAllocator.js +0 -196
- package/src/core/WorkerChannelManager.js +0 -879
- package/src/core/config.js +0 -637
- package/src/core/host-config.js +0 -311
- package/src/core/network-utils.js +0 -166
- package/src/core/platform-config.js +0 -308
- package/src/decorators/ServiceProxy.js +0 -904
- package/src/decorators/index.js +0 -571
- package/src/deploy/NginxGenerator.js +0 -865
- package/src/deploy/PlatformManifestGenerator.js +0 -96
- package/src/deploy/RouteManifestGenerator.js +0 -112
- package/src/deploy/index.js +0 -984
- package/src/frontend/FrontendDevLifecycle.js +0 -65
- package/src/frontend/FrontendPluginOrchestrator.js +0 -187
- package/src/frontend/SiteResolver.js +0 -63
- package/src/frontend/StaticMountRegistry.js +0 -90
- package/src/frontend/plugins/viteFrontend.js +0 -79
- package/src/frontend/types.js +0 -35
- package/src/index.js +0 -58
- package/src/plugins/PluginManager.js +0 -537
- package/src/plugins/ScopedPostgres.js +0 -192
- package/src/plugins/ScopedRedis.js +0 -142
- package/src/plugins/index.js +0 -1756
- package/src/registry/ServiceRegistry.js +0 -797
- package/src/scaling/ScaleAdvisor.js +0 -442
- package/src/services/Service.js +0 -195
- package/src/services/worker-bootstrap.js +0 -679
- package/src/templates/auth-service.js +0 -65
- package/src/templates/identity-service.js +0 -75
package/README.md
CHANGED
|
@@ -17,14 +17,29 @@ Node.js runs on a single thread. Modern servers have 16, 32, 64+ cores. ThreadFo
|
|
|
17
17
|
- **Auto-restart** — crashed workers are automatically replaced
|
|
18
18
|
- **Runtime scaling** — scale services up/down without restarting
|
|
19
19
|
- **RequestContext propagation** — correlation IDs, auth, deadlines, and baggage across services
|
|
20
|
-
- **Built-in metrics** — Prometheus-compatible endpoint
|
|
20
|
+
- **Built-in metrics** — Prometheus-compatible endpoint with HTTP, RPC, and event loop lag metrics
|
|
21
21
|
- **Multi-machine deployment** — grow from one machine to a full cluster with `forge.deploy.js`
|
|
22
22
|
|
|
23
23
|
## Quick Start
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
### Option 1: Install from npm (Recommended)
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
```bash
|
|
28
|
+
# Create and scaffold a new project
|
|
29
|
+
mkdir my-app && cd my-app
|
|
30
|
+
npm init -y
|
|
31
|
+
npm install threadforge
|
|
32
|
+
npx forge init . --source npm
|
|
33
|
+
npm install
|
|
34
|
+
|
|
35
|
+
# Start in development mode (hot reload)
|
|
36
|
+
npm run dev
|
|
37
|
+
|
|
38
|
+
# Start in production mode
|
|
39
|
+
npm run start
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Option 2: Local Development (ThreadForge contributors only)
|
|
28
43
|
|
|
29
44
|
```bash
|
|
30
45
|
# Clone and link ThreadForge locally
|
|
@@ -43,36 +58,17 @@ npm install
|
|
|
43
58
|
npm run dev
|
|
44
59
|
```
|
|
45
60
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
# Scaffold a new project
|
|
50
|
-
npx github:ChrisBland/threadforge init my-app
|
|
51
|
-
cd my-app
|
|
52
|
-
npm install
|
|
53
|
-
|
|
54
|
-
# Start in development mode (hot reload)
|
|
55
|
-
npm run dev
|
|
56
|
-
|
|
57
|
-
# Start in production mode
|
|
58
|
-
npm run start
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
If `npx github:ChrisBland/threadforge ...` fails with npm cache permission errors (`EPERM` on `~/.npm/_cacache`), use a writable cache directory for the command:
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
NPM_CONFIG_CACHE=/tmp/threadforge-npm-cache npx github:ChrisBland/threadforge init my-app
|
|
65
|
-
```
|
|
61
|
+
`forge init` is backend-only by default. Add static frontend scaffolding with `npx forge scaffold frontend` (or `npx forge init . --with-frontend`), or generate Vite + React with `npx forge scaffold frontend --react` (or `npx forge init . --with-react`).
|
|
66
62
|
|
|
67
63
|
Create `forge.config.js`:
|
|
68
64
|
|
|
69
65
|
```javascript
|
|
70
|
-
import { defineServices } from 'threadforge';
|
|
66
|
+
import { defineServices, ServiceType } from 'threadforge';
|
|
71
67
|
|
|
72
68
|
export default defineServices({
|
|
73
69
|
api: {
|
|
74
70
|
entry: './services/api.js',
|
|
75
|
-
type:
|
|
71
|
+
type: ServiceType.EDGE,
|
|
76
72
|
port: 3000,
|
|
77
73
|
threads: 'auto',
|
|
78
74
|
connects: ['users'],
|
|
@@ -80,7 +76,7 @@ export default defineServices({
|
|
|
80
76
|
|
|
81
77
|
users: {
|
|
82
78
|
entry: './services/users.js',
|
|
83
|
-
type:
|
|
79
|
+
type: ServiceType.INTERNAL,
|
|
84
80
|
},
|
|
85
81
|
});
|
|
86
82
|
```
|
|
@@ -88,15 +84,10 @@ export default defineServices({
|
|
|
88
84
|
Create `services/api.js`:
|
|
89
85
|
|
|
90
86
|
```javascript
|
|
91
|
-
import { Service } from 'threadforge';
|
|
87
|
+
import { HttpMethod, Service, Route } from 'threadforge';
|
|
92
88
|
|
|
93
89
|
export default class ApiService extends Service {
|
|
94
|
-
|
|
95
|
-
routes: [
|
|
96
|
-
{ method: 'GET', path: '/users/:id', handler: 'getUser' },
|
|
97
|
-
],
|
|
98
|
-
};
|
|
99
|
-
|
|
90
|
+
@Route(HttpMethod.GET, '/users/:id')
|
|
100
91
|
async getUser(body, params) {
|
|
101
92
|
return await this.users.getUser(params.id);
|
|
102
93
|
}
|
|
@@ -106,29 +97,63 @@ export default class ApiService extends Service {
|
|
|
106
97
|
Create `services/users.js`:
|
|
107
98
|
|
|
108
99
|
```javascript
|
|
109
|
-
import { Service } from 'threadforge';
|
|
100
|
+
import { Service, Expose } from 'threadforge';
|
|
110
101
|
|
|
111
102
|
export default class UsersService extends Service {
|
|
112
|
-
static contract = {
|
|
113
|
-
expose: ['getUser'],
|
|
114
|
-
};
|
|
115
|
-
|
|
116
103
|
async onStart(ctx) {
|
|
117
104
|
this.store = new Map([['1', { id: '1', name: 'Alice' }]]);
|
|
118
105
|
}
|
|
119
106
|
|
|
107
|
+
@Expose()
|
|
120
108
|
async getUser(id) {
|
|
121
|
-
return this.store.get(String(id));
|
|
109
|
+
return this.store.get(String(id)) ?? null;
|
|
122
110
|
}
|
|
123
111
|
}
|
|
124
112
|
```
|
|
125
113
|
|
|
126
114
|
```bash
|
|
127
|
-
|
|
115
|
+
npm run start
|
|
128
116
|
# curl http://localhost:3000/users/1
|
|
129
|
-
# → {
|
|
117
|
+
# → {"id":"1","name":"Alice"}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Platform Mode Quick Flow
|
|
121
|
+
|
|
122
|
+
For multi-site projects (multiple apps/domains with per-app services/frontends):
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
mkdir platform-app && cd platform-app
|
|
126
|
+
npm init -y
|
|
127
|
+
npm install threadforge
|
|
128
|
+
npx forge platform init
|
|
129
|
+
npx forge platform add sitea
|
|
130
|
+
npx forge platform add siteb
|
|
131
|
+
|
|
132
|
+
# then edit forge.platform.js:
|
|
133
|
+
# - add platform.apps.<appId> with domains/services/frontend
|
|
134
|
+
# - add top-level '<appId>-api' service entries with unique ports
|
|
135
|
+
# - register frontendPlugins (for example: viteFrontend())
|
|
136
|
+
# - create each frontend project (for example: apps/sitea/web and apps/siteb/web)
|
|
137
|
+
|
|
138
|
+
# install frontend deps for each site before build
|
|
139
|
+
# (example)
|
|
140
|
+
# cd apps/sitea/web && npm install
|
|
141
|
+
# cd ../../siteb/web && npm install
|
|
142
|
+
# cd ../../../
|
|
143
|
+
|
|
144
|
+
npx forge build
|
|
145
|
+
npx forge platform generate
|
|
146
|
+
npx forge platform start
|
|
130
147
|
```
|
|
131
148
|
|
|
149
|
+
See:
|
|
150
|
+
- `docs/guides/plugins.md` for frontend plugin config (`viteFrontend`)
|
|
151
|
+
- `docs/reference/configuration.md` for `definePlatform()` schema
|
|
152
|
+
- `docs/reference/cli.md` for all `forge platform` subcommands
|
|
153
|
+
- `examples/platform-two-app-react-date-time/README.md` for a runnable two-site date/time + React example
|
|
154
|
+
- `examples/platform-kitchen-sink/README.md` for shared auth/users + event-driven multi-site example
|
|
155
|
+
- `examples/threads-overprovision/README.md` for graceful handling when requested threads exceed host CPU capacity
|
|
156
|
+
|
|
132
157
|
## Documentation
|
|
133
158
|
|
|
134
159
|
Full documentation is in the [`docs/`](./docs/) directory:
|
|
@@ -136,16 +161,18 @@ Full documentation is in the [`docs/`](./docs/) directory:
|
|
|
136
161
|
- [**Getting Started**](./docs/getting-started.md) — Install, create your first service, and run it
|
|
137
162
|
- [**Architecture**](./docs/architecture.md) — Process model, communication layers, request lifecycle
|
|
138
163
|
- **Guides:**
|
|
164
|
+
- [Single-App React Date/Time Quickstart](./docs/guides/single-app-react-date-time.md) — One app with `/time`, `/date`, and a React frontend
|
|
139
165
|
- [Services](./docs/guides/services.md) — Types, lifecycle, colocation, plain JS fallback
|
|
140
166
|
- [IPC & Communication](./docs/guides/ipc.md) — Proxy clients, events, interceptors
|
|
141
167
|
- [Plugins](./docs/guides/plugins.md) — Redis, PostgreSQL, S3, CORS, Cron, Realtime
|
|
168
|
+
- [Platform Two-App React Quickstart](./docs/guides/platform-two-app-react.md) — Multi-site apps with per-site API + frontend
|
|
142
169
|
- [Deployment](./docs/guides/deployment.md) — Single machine to multi-machine scaling
|
|
143
170
|
- **Reference:**
|
|
144
171
|
- [Configuration](./docs/reference/configuration.md) — All `forge.config.js` options
|
|
145
172
|
- [Decorators](./docs/reference/decorators.md) — Full decorator API
|
|
146
173
|
- [CLI](./docs/reference/cli.md) — Commands, options, metrics endpoints
|
|
147
174
|
- [API](./docs/reference/api.md) — All public exports
|
|
148
|
-
- [**ForgeProxy**](./docs/
|
|
175
|
+
- [**ForgeProxy**](./docs/architecture.md#three-layer-production-architecture) — Rust gateway architecture and ingress role
|
|
149
176
|
|
|
150
177
|
## License
|
|
151
178
|
|