feat(compiler): emit the server-side api object
Server module now declares `const api = { ... }` for apis {} blocks in
mode "any", dispatching in-process via requireRequestContext + the
existing __wrnexusCallApi transport helper. The try wraps only the
transport call; the response body runs after it, outside the try, so
a bug in the author's response code surfaces rather than being
mistaken for a request failure. A block with no error {} section
rethrows instead of resolving undefined.
Also closes the pageCtx.__wrnexusCallApi wiring gap in
dev-server/runtime.ts: it now forwards input through to
callApiFromContext instead of dropping it.
This commit is contained in:
@@ -1773,10 +1773,15 @@ export function createHandlers(deps: RuntimeDeps): Handlers {
|
||||
?.filter((value, index, values) => values.indexOf(value) === index)
|
||||
.join(",");
|
||||
const pageCtx = ctx as Context & {
|
||||
__wrnexusCallApi?: (path: string, method?: string) => Promise<unknown>;
|
||||
__wrnexusCallApi?: (
|
||||
path: string,
|
||||
method?: string,
|
||||
input?: Record<string, unknown>,
|
||||
) => Promise<unknown>;
|
||||
__wrnexusUseStore?: (definition: StoreDefinition<any, any, any>) => Promise<unknown>;
|
||||
};
|
||||
pageCtx.__wrnexusCallApi = (path, method = "GET") => callApiFromContext(ctx, path, method);
|
||||
pageCtx.__wrnexusCallApi = (path, method = "GET", input) =>
|
||||
callApiFromContext(ctx, path, method, input);
|
||||
pageCtx.__wrnexusUseStore = (definition) => storeContainer.use(definition);
|
||||
const load = mod.__wrnexusLoad as ((ctx: Context) => Promise<unknown>) | undefined;
|
||||
if (typeof load === "function") {
|
||||
|
||||
Reference in New Issue
Block a user