@pablozaiden/webapp 0.6.3 → 0.6.4
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/docs/server.md
CHANGED
|
@@ -106,6 +106,31 @@ Route context is user-aware:
|
|
|
106
106
|
|
|
107
107
|
Use `ctx.filterOwned(records, getUserId)` and `ctx.requireOwned(record, getUserId)` when app records use a different ownership field. Return 404 for other-user resources so route responses do not reveal whether another user's id exists.
|
|
108
108
|
|
|
109
|
+
## Supplying a validated runtime config
|
|
110
|
+
|
|
111
|
+
`createWebAppServer` reads and validates `{PREFIX}_*` environment variables by
|
|
112
|
+
default. An application that has already resolved a `RuntimeConfig` can pass it
|
|
113
|
+
through `runtimeConfig` instead:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { createWebAppServer, readRuntimeConfig } from "@pablozaiden/webapp/server";
|
|
117
|
+
|
|
118
|
+
const runtimeConfig = readRuntimeConfig({ appName: "My App", envPrefix: "MY_APP" });
|
|
119
|
+
const app = createWebAppServer({
|
|
120
|
+
appName: "My App",
|
|
121
|
+
envPrefix: "MY_APP",
|
|
122
|
+
runtimeConfig,
|
|
123
|
+
routes,
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The supplied config is used during every framework initialization step,
|
|
128
|
+
including store selection, logging, authentication, document generation,
|
|
129
|
+
request handling, and lifecycle setup. Its `appName` and `envPrefix` must match
|
|
130
|
+
the constructor inputs. Do not mutate `app.config` after construction to
|
|
131
|
+
replace constructor options; omit `runtimeConfig` when the framework should read
|
|
132
|
+
the environment itself.
|
|
133
|
+
|
|
109
134
|
Built-in endpoints include:
|
|
110
135
|
|
|
111
136
|
| Endpoint | Purpose |
|
package/package.json
CHANGED
|
@@ -41,7 +41,10 @@ function canUseSpaFallback(req: Request): boolean {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function createWebAppServer<TEvent = unknown>(input: WebAppServerConfig<TEvent>): WebAppServer<TEvent> {
|
|
44
|
-
const config = readRuntimeConfig({ appName: input.appName, envPrefix: input.envPrefix });
|
|
44
|
+
const config = input.runtimeConfig ?? readRuntimeConfig({ appName: input.appName, envPrefix: input.envPrefix });
|
|
45
|
+
if (config.appName !== input.appName || config.envPrefix !== input.envPrefix) {
|
|
46
|
+
throw new Error("runtimeConfig appName and envPrefix must match the createWebAppServer inputs");
|
|
47
|
+
}
|
|
45
48
|
const store = input.store ?? sqliteWebAppStore({ dataDir: config.dataDir });
|
|
46
49
|
store.initialize();
|
|
47
50
|
const savedLogLevel = store.getLogLevelPreference();
|