Skip to content

feat(start): in-process mode (createServer, no jss spawn) — embeddable jspod#59

Closed
melvincarvalho wants to merge 1 commit into
issue-56-programmatic-apifrom
issue-58-inprocess-start
Closed

feat(start): in-process mode (createServer, no jss spawn) — embeddable jspod#59
melvincarvalho wants to merge 1 commit into
issue-56-programmatic-apifrom
issue-58-inprocess-start

Conversation

@melvincarvalho
Copy link
Copy Markdown
Contributor

Summary

Adds an in-process mode to the programmatic start() API: start({ inProcess: true }) runs JSS via javascript-solid-server's createServer().listen() in the current process instead of spawning the jss binary.

This lets jspod embed in single-process runtimes — nodejs-mobile (the Android app, js-pod/android), Electron, tests — where forking a CLI binary isn't possible. Today the Android app bypasses jspod entirely and calls createServer directly, losing jspod's onboarding/bundling and drifting off jspod's JSS version; with this it can use jspod as the wrapper.

Closes #58.

What it does

  • Maps the same options the spawn path builds as jss CLI args to a createServer options object (root, port, host, conneg, notifications, git, mashlibModule, idp/public, singleUser/singleUserPassword, provisionKeys, idpIssuer).
  • Sets TOKEN_SECRET in env (JSS reads it there) and listens.
  • Returns the same handle shape as the spawn path — { url, port, host, root, ready, exit, stop } — plus inProcess: true and server (the Fastify instance) for advanced embedders.
  • Factors the post-readiness work (seedPodFiles + bootstrap + open) into a shared afterReady() used by both paths, so the in-process pod still gets jspod's seeded welcome/signin/account pages.
  • idpIssuer is passed with a trailing slash so it matches JSS's discovery-doc issuer (RFC 9207 / strict solid-oidc clients).

Tested (this machine, no spawn)

  • Pod boots in-process: "Server listening", inProcess: true.
  • GET / 200, /.well-known/openid-configuration 200 (issuer http://localhost:PORT/), /idp 200.
  • seedPodFiles ran (GET / body grew from the bare-JSS index to jspod's welcome page).
  • stop() closes cleanly.

Known follow-up (not in this PR)

Bootstrap installs apps via git clone + push to the pod's git-receive endpoint. That needs a git binary and child-process spawning — unavailable in git-less single-process runtimes (nodejs-mobile). There the bootstrap's error handler fires harmlessly and the embedder seeds apps its own way (the Android app uses a jsDelivr fetch). A git-less install path (fetch files + write/PUT) is the natural next step so embedders inherit jspod's bundling too.

Notes

  • Base is issue-56-programmatic-api (this stacks on the programmatic start() API; that branch isn't on gh-pages yet).
  • Spawn path behavior is unchanged.

Adds `start({ inProcess: true })`: maps the same options to
javascript-solid-server's createServer() and listens in the current
process instead of spawning the `jss` binary. Lets jspod embed in
single-process runtimes (nodejs-mobile, Electron, tests) where forking
a CLI isn't possible, while still returning the same handle shape
(url/port/host/root/ready/exit/stop, plus the Fastify instance).

Post-readiness logic (seedPodFiles + bootstrap + open) is factored into
a shared afterReady() used by both paths, so the in-process pod gets the
same jspod onboarding pages.

Note: bootstrap still installs apps via git clone+push, which needs git
+ child-process spawning — unavailable in git-less runtimes (Android).
There the 'error' handler fires harmlessly and the embedder seeds apps
itself; a git-less install is a follow-up. Refs #58.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant