Modify the cli to initialize fpx. This runs a small wizard that creates a local configuration folder, and a (versioned) configuration file.
Update the middleware to only send log/trace/event data to the fpx api when an FPX_ENDPOINT is defined in the user's api's environment
(2) Is very simple, just changed a few lines of code in the client-library, so the rest of this description will focus on (1)
Initializing FPX from the CLI
The CLI will create (or read from) .fpxconfig/fpx.config.v0.json. This is assumed to be an object whose keys are environment variables. These are considered "User Variables".
{
"FPX_SERVICE_TARGET": "8787",
"FPX_PORT": "8788",
// This database file path will be set based off of platform (windows vs *nix-like)
"FPX_DATABASE_URL": "file:.fpxconfig/fpx.db"
}
When determining the port on which FPX studio should run, it checks:
process.env.FPX_PORT
FPX_PORT from the User Variables (config file in project)
It falls back to asking the user for the port on which it should run. The default is 8788.
When determining the url for the user's service, it checks:
process.env.FPX_SERVICE_TARGET
FPX_SERVICE_TARGET from the User Variables
The [dev.port] defined in the wrangler.toml file, if one exists
Then, it also silently configures the service name based on what's in wrangler.toml or package.json (if one exists).
In addition to the above it:
Checks if the FPX_PORT is available, and suggests a new one if it is not
Checks if the user's api is running, and reminds them to start it if it is not
Creates .dev.vars if one does not exist (and if we detect a wrangler.toml file)
Asks permission to modify the env var file to update FPX_ENDPOINT accordingly, if it is out of date where we'll serve the studio
Testing locally
There are instructions in the api readme for this, but @keturiosakys pointed out it's also possible to just run
npx ../path/to/fpx/api
But! You need to build the studio before running that.
cd /path/to/fpx
# from the project root!
npm run build:fpx-studio
Demo
https://github.com/fiberplane/fpx/assets/3201327/81125a08-e62f-4afa-b64f-75f517d405d2
Description
This PR does two things:
FPX_ENDPOINT
is defined in the user's api's environment(2) Is very simple, just changed a few lines of code in the
client-library
, so the rest of this description will focus on (1)Initializing FPX from the CLI
The CLI will create (or read from)
.fpxconfig/fpx.config.v0.json
. This is assumed to be an object whose keys are environment variables. These are considered "User Variables".When determining the port on which FPX studio should run, it checks:
process.env.FPX_PORT
FPX_PORT
from the User Variables (config file in project)It falls back to asking the user for the port on which it should run. The default is 8788.
When determining the url for the user's service, it checks:
process.env.FPX_SERVICE_TARGET
FPX_SERVICE_TARGET
from the User Variables[dev.port]
defined in thewrangler.toml
file, if one existsThen, it also silently configures the service name based on what's in wrangler.toml or package.json (if one exists).
In addition to the above it:
.dev.vars
if one does not exist (and if we detect a wrangler.toml file)FPX_ENDPOINT
accordingly, if it is out of date where we'll serve the studioTesting locally
There are instructions in the api readme for this, but @keturiosakys pointed out it's also possible to just run
But! You need to build the studio before running that.