Per-Service URLs and Automatic Port Mapping
Give each named service its own public or private URL. Sprites handles the port mapping, so no reverse proxy is needed.
On this page
What it is
Inside a Sprite you register services: long-running processes such as a web app, an admin dashboard, an API or a database. Every HTTP service automatically gets its own URL, and Sprites routes traffic to the right port for you.
- No reverse proxy: you don’t run nginx or Caddy to map hostnames to ports.
- Per-service access control: each URL is private until you make it public, and you choose for each service separately.
- Internal-only, if you like: a service doesn’t have to be exposed at all. Other Sprites can reach it over the Sprite internal network with a service grant.
- Supervised: services restart according to their policy and start again whenever the Sprite wakes.
Step by step: an app and a private dashboard
We’ll take a Sprite named dev with two services:
http: the main app, on port 8080. It will be public.dashboard: an admin dashboard on port 3000. It will stay private.
1. Register the services
Inside dev (via ssh dev--default--my-org@sprites.dev):
sprite-env service register http --port 8080 --protocol http -- npm start
sprite-env service register dashboard --port 3000 --protocol http \
-- npm run dashboard
Everything after -- is the command to run. Your app must listen on the port you declare, on 0.0.0.0.
You can do the same from outside:
ssh my-org@sprites.dev sprite service register dev dashboard \
--port 3000 --protocol http --restart always -- npm run dashboard
# HTTP API
curl -sS -X PUT "https://api.sprites.dev/v1/sprites/dev/services/dashboard" \
-H "Authorization: Bearer $SPRITES_TOKEN" \
-H "Content-Type: application/json" -d '{
"endpoint": {"port": 3000, "protocol": "http"},
"restart": "always",
"process": {"argv": ["npm", "run", "dashboard"]}}'
2. Check they’re running
sprite-env service list
sprite-env service status http
sprite-env service logs http
To see whether a service is actually listening yet, check from outside the Sprite. The status shows runtime.ready: true once the service listens on its port:
ssh my-org@sprites.dev sprite service status dev http
curl -sS "https://api.sprites.dev/v1/sprites/dev/services/http" \
-H "Authorization: Bearer $SPRITES_TOKEN"
3. Find the URLs
The http service is the Sprite’s main web server. It answers at the Sprite’s short URL and a long form:
https://dev-b35zb.sprites.app/
https://http--dev--default--my-org.sprites.app/
(Your short URL is the url field in sprite get dev.)
Any other service answers only at its own long address:
https://dashboard--dev--default--my-org.sprites.app/
The pattern is SERVICE--SPRITE--CLUSTER--ORG.sprites.app.
4. Try them while they’re private
A private URL answers only your organization:
In a browser, you’re sent to sign in.
From scripts, send an organization token:
curl -H "Authorization: Bearer $SPRITES_TOKEN" https://dev-b35zb.sprites.app/
Requests without a valid token are redirected to the sign-in page (302). Clients that send Accept: application/json get 401 instead.
5. Make the app public
ssh my-org@sprites.dev sprite update dev --public
# HTTP API
curl -sS -X PUT "https://api.sprites.dev/v1/sprites/dev" \
-H "Authorization: Bearer $SPRITES_TOKEN" \
-H "Content-Type: application/json" \
-d '{"url_settings":{"auth":"public"}}'
The app is now open to the internet. The dashboard is still private: making http public never opens another service.
6. Check the settings
ssh my-org@sprites.dev sprite get dev
"url_settings": {"auth": "public",
"services": {"dashboard": {"auth": "sprite"}}}
auth is the http service. services lists every other HTTP service. public is open; sprite is private.
Switching services public and private
# Make the dashboard public too
ssh my-org@sprites.dev sprite update dev --public-service dashboard
# Close the dashboard again
ssh my-org@sprites.dev sprite update dev --private-service dashboard
# Close the app
ssh my-org@sprites.dev sprite update dev --private
# Several at once
ssh my-org@sprites.dev sprite update dev --private --public-service dashboard
# HTTP API
curl -sS -X PUT "https://api.sprites.dev/v1/sprites/dev" \
-H "Authorization: Bearer $SPRITES_TOKEN" \
-H "Content-Type: application/json" \
-d '{"url_settings":{"services":{"dashboard":{"auth":"public"}}}}'
curl -sS -X PUT "https://api.sprites.dev/v1/sprites/dev" \
-H "Authorization: Bearer $SPRITES_TOKEN" \
-H "Content-Type: application/json" \
-d '{"url_settings":{"auth":"sprite"}}'
Send url_settings in a request of its own, not combined with other updates.
Keeping a service internal
Not every service should be on the internet. A database, cache or internal API can stay private and be reached only by the Sprites you choose, through a service grant:
# Let Sprites labeled `api` reach the `db` TCP service on `storage`.
ssh my-org@sprites.dev "service-grant create api-to-db \
--scope cluster --cluster review-123 \
--source-label api --target storage/db"
Inside a granted Sprite, the service is at db--storage.sprite.internal:5432 (or http://SERVICE--SPRITE.sprite.internal/ for HTTP). This works for both HTTP and TCP services, and needs no public URL.
Choosing how a service is reached:
| Who needs it? | Do this |
|---|---|
| Anyone on the internet | Make its URL public |
| You and your organization | Leave its URL private (the default) |
| Only specific other Sprites | Leave it private and add a service grant |
| Just you, from your laptop | SSH port forwarding |
Declaring services when you create a Sprite
You can declare service endpoints up front with NAME:PORT[:http|tcp]:
ssh my-org@sprites.dev sprite create storage --service http:8080 --service db:5432:tcp
# HTTP API
curl -sS -X POST "https://api.sprites.dev/v1/sprites" \
-H "Authorization: Bearer $SPRITES_TOKEN" \
-H "Content-Type: application/json" -d '{
"name": "storage",
"services": {"http": {"endpoint": {"port": 8080, "protocol": "http"}},
"db": {"endpoint": {"port": 5432, "protocol": "tcp"}}}}'
Service options
| Option | CLI flag | Meaning |
|---|---|---|
| Port & protocol | --port, --protocol | Where it listens; http (default) or tcp. |
| Command | -- COMMAND... or --argv '[...]' | What to run. |
| Restart policy | --restart | always (default), on-failure, or never. |
| Working dir / env | --cwd, --env KEY=VALUE | Process environment. |
| Dependencies | needs (JSON) | Services to start first. |
| Stop behavior | --stop-signal, --stop-grace-ms | Signal to send (default SIGTERM) and time before kill (default 10000, max 20000). |
| Description | --description | Shown in discovery; explain the protocol for agents. |
Up to 32 services per Sprite. Names use lowercase letters, digits and -, with no -- and no sprite prefix.
Manage services with:
sprite-env service restart http
sprite-env service stop http
sprite-env service start http
What callers see while a service starts
Services start again on every wake. A request to a service that is still starting waits until it listens.
| Response | Cause |
|---|---|
504 Gateway Timeout (after about 30 s) | The service didn’t start listening in time. |
503 service_not_running | The service is stopped or crashed. |
502 internal_error | No service process owns the port. |
404 public_service_not_found | No service with that name exists on the Sprite. |
Things to know about public URLs
- Only HTTP services can be public. Making a TCP service public fails with
public_service_not_http. Reach TCP services from other Sprites through the internal network, or from your laptop with SSH port forwarding. - A service must exist before you make it public. The setting stays with its name: delete
dashboardand register it again, and it’s public again. Make it private first if it shouldn’t be. - Deleting a Sprite closes its URLs. A new Sprite with the same name starts private.
- The platform doesn’t check the caller’s
Authorizationheader on a public URL, and it reaches your app unchanged. If your app has its own login, it must validate that header itself (or use cookies), and you shouldn’t treat its presence as proof the platform authenticated anyone. - Identity headers: requests to a service’s long address carry
x-sprite-public-internet: trueplusx-sprite-org-id,x-sprite-cluster-id,x-sprite-nameandx-sprite-ref. The Sprite’s short URL sendsx-sprite-idinstead ofx-sprite-nameand omitsx-sprite-public-internet. The platform sets these headers and drops anyx-sprite-*headers a caller tries to send.
Making a service public across a pool of Sprites
Rather than switching each Sprite, use an org-scoped grant from the reserved sprite_public_internet source. This makes dashboard public on every Sprite labeled public-dashboard:
ssh my-org@sprites.dev "service-grant create public-dashboards \
--scope org \
--service dashboard \
--source-label sprite_public_internet \
--target-label public-dashboard"
A grant opens only the service’s long address. For http, use --public to open the Sprite’s short URL.
Running Docker containers as services
Install Docker and run dockerd as a service so it comes back after every stop, restore and fork:
sudo apt-get update && sudo apt-get install -y docker.io
sprite-env services create dockerd --restart always -- sudo /usr/bin/dockerd
sudo docker run -d --restart unless-stopped --name web -p 8081:80 nginx:alpine
services create starts the daemon right away. The example maps nginx to port 8081 because the http service in this walkthrough already uses 8080; register -p 8081 as a service port if you want a URL for it.
Start containers with --restart unless-stopped (or always) so they come back with the daemon. Don’t start dockerd from a shell; it won’t be restarted.