-
Notifications
You must be signed in to change notification settings - Fork 13
docs(agent): document the embedded BFF and the mount order it needs #1877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8c74fbf
docs(agent): document the embedded BFF and the mount order it needs
nbouliol aeb9a4a
docs(agent): fix the mountless quick-starts and pin the cors hazard
nbouliol c612b1e
fix(agent): call supertest by the name the e2e suite imports it under
nbouliol 7f0902e
docs(agent): correct three statements the rebased code no longer matches
nbouliol a4679e6
docs(agent-bff): name the one control the embedded mode does not apply
nbouliol 3c34a4a
docs(agent): resync the three paragraphs the stack moved under
nbouliol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # @forestadmin/agent | ||
|
|
||
| The main entry point of the Forest Admin Node.js SDK: `createAgent(options)` returns an agent to | ||
| which you attach datasources, customizations, charts and plugins, then mount on your HTTP server. | ||
|
|
||
| See the [developer guide](https://docs.forestadmin.com/developer-guide-agents-nodejs) for the full | ||
| documentation. | ||
|
|
||
| ## Optional in-process components | ||
|
|
||
| Two components normally deployed on their own can run inside the agent instead. Both are optional | ||
| packages, loaded dynamically: an agent that does not use them never loads their code. | ||
|
|
||
| ### A BFF — `agent.addBff()` | ||
|
|
||
| ```bash | ||
| npm install @forestadmin/agent-bff | ||
| ``` | ||
|
|
||
| ```ts | ||
| await createAgent(options) | ||
| .addDataSource(/* … */) | ||
| .addBff({ allowedOrigins: ['https://my-app.com'] }) | ||
| .mountOnStandaloneServer(3351) | ||
| .start(); | ||
| ``` | ||
|
|
||
| Serves the REST BFF under `/bff` on whatever port the agent is mounted on, on every mount target — | ||
| `mountOnStandaloneServer` above, or the host's own listener with `mountOnExpress`, `mountOnKoa`, | ||
| `mountOnFastify`, `mountOnNestJs`. A `mountOn*` call is what opens a socket: `start()` only builds | ||
| the agent's router, so a chain without one serves nothing, BFF included. | ||
|
|
||
| The BFF reaches the agent in the same process, so there is no second port, no agent url to | ||
| configure, and no secrets to keep in sync — `authSecret`, `envSecret`, the Forest urls and the | ||
| logger are inherited. | ||
|
|
||
| Everything `addBff()` takes is a feature it switches on: `tokenEncryptionKey` enables OAuth (and | ||
| with it the AI relay), `allowedOrigins` enables browser access, `openapiEnabled` serves the docs | ||
|
Tonours marked this conversation as resolved.
|
||
| (off by default when embedded). `GET /bff/health` reports which of them are on, under `configured`. | ||
|
|
||
| **Mount the agent before any body parser of your own** — a parser that runs first consumes the | ||
| request stream, and every BFF `POST` then answers `500 stream.not.readable`. | ||
|
|
||
| A permissive `cors()` registered ahead of the mount costs you the preflight but not the allow-list: | ||
| the host answers `OPTIONS` with its own policy, and nothing downstream can take that back, so the | ||
| request that follows arrives here anyway — and is refused with `403 origin_not_allowed` unless its | ||
| `Origin` is one you listed. The browser sees the wrong preflight; the collection is still never read | ||
| for that origin. | ||
|
|
||
| Mounting under a sub-path of your own works: `app.use('/api', mounted)` serves the BFF at | ||
| `/api/bff`, and the prefix is derived per request, so the OpenAPI `servers` entry and the docs page | ||
| carry `/api/bff` too. | ||
|
|
||
| **`agentTimeoutMs` bounds the wait, not the work.** When a call to the agent exceeds it the BFF | ||
| answers with an error, but nothing is cancelled: the in-process request runs to completion. An | ||
| action cut at the timeout still applies its mutation, so a client that retries applies it twice. | ||
| Size the timeout above your slowest action, and make actions idempotent if you intend to retry them. | ||
|
|
||
| **`addBff()` cannot be combined with `mountAiMcpServer({ basePath: '/bff' })`** — the MCP server | ||
| would claim `/bff/oauth` and `/bff/mcp`. Whichever you call second throws on the spot, at the | ||
| builder call and not from `start()`. | ||
|
|
||
| See [`@forestadmin/agent-bff`](../agent-bff/README.md) for the routes, the auth modes and the | ||
| differences with the standalone deployment. | ||
|
|
||
| ### A workflow executor — `agent.addWorkflowExecutor()` | ||
|
Tonours marked this conversation as resolved.
|
||
|
|
||
| ```bash | ||
| npm install @forestadmin/workflow-executor | ||
| ``` | ||
|
|
||
| Runs a workflow executor alongside the agent, which proxies `/_internal/executor/*` to it. See | ||
| [`@forestadmin/workflow-executor`](../workflow-executor/README.md). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.