Skip to content

Commit 4e43cf2

Browse files
authored
Merge pull request #28 from superfly/networking-page-edits
Update Sprites networking docs: rewrite for length/tone
2 parents 493e41f + c90e3bf commit 4e43cf2

File tree

1 file changed

+53
-162
lines changed

1 file changed

+53
-162
lines changed

src/content/docs/concepts/networking.mdx

Lines changed: 53 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,35 @@ description: HTTP access, URLs, port forwarding, and network configuration
66
import { Tabs, TabItem } from '@astrojs/starlight/components';
77
import { Snippet } from '@/components/react';
88

9-
Every Sprite has built-in networking capabilities including a unique HTTP URL and port forwarding. This page covers how to access your Sprites over the network.
9+
Sprites run your code in the cloud. This page is about how to talk to that code via HTTPS URLs and port forwarding that make remote services feel local. You get a public endpoint to hit your app over the Internet, and the ability to proxy ports straight to your laptop so you can test, debug, and connect tools like you're running everything on localhost.
1010

1111
## Sprite URLs
1212

13-
Every Sprite has a unique URL for HTTP access:
13+
Every Sprite has a unique URL for HTTPS access, for example:
1414

1515
```bash
1616
sprite url
1717
# Output: https://my-sprite-abc123.sprites.dev
1818
```
1919

20-
This URL can be used to:
20+
If your code is listening on a port (say, 3000 or 8080), that URL routes traffic to it. This means you can:
2121

2222
- Access web applications running in your Sprite
23+
- Test a dev server in the cloud
2324
- Make API requests to services
24-
- Connect to any HTTP-based service
25+
- Connect services to each other via HTTP
2526

2627
### URL Authentication
2728

28-
By default, Sprite URLs require authentication. You can configure this:
29+
By default, Sprite URLs are private and they require a valid token. You can make them public if you want to share a demo, open up a webhook, or quickly put something onto the Internet:
2930

3031
<Tabs>
3132
<TabItem label="CLI">
3233
```bash
33-
# Make URL public (no authentication required)
34+
# Make URL public (no authentication required) - good for webhooks, public APIs, demos
3435
sprite url update --auth public
3536

36-
# Require sprite authentication (default)
37+
# Require sprite authentication (default) - good for internal services, development
3738
sprite url update --auth default
3839
```
3940
</TabItem>
@@ -47,32 +48,15 @@ console.log(info.url);
4748
</TabItem>
4849
</Tabs>
4950

50-
| Auth Mode | Description | Use Case |
51-
|-----------|-------------|----------|
52-
| `sprite` | Requires Sprite token | Internal services, development |
53-
| `public` | No authentication | Public APIs, webhooks, demos |
54-
5551
Updating URL settings is available via the CLI, Go SDK, or REST API (the JS SDK does not expose a helper yet).
5652

57-
### Starting a Web Server
58-
59-
Run a web server and access it via the Sprite URL:
60-
61-
```bash
62-
# Start a simple HTTP server
63-
sprite exec -detachable "python -m http.server 8080"
64-
65-
# Get the URL
66-
sprite url
67-
# Output: https://my-sprite-abc123.sprites.dev
53+
## Port Forwarding
6854

69-
# Access via browser or curl (after making public)
70-
curl https://my-sprite-abc123.sprites.dev:8080/
71-
```
55+
Here's the trick that makes Sprites feel local: port forwarding.
7256

73-
## Port Forwarding
57+
Now your laptop's localhost:3000 forwards to the Sprite's port 3000. You can open a browser, curl it, or connect with tools that expect a local port.
7458

75-
Forward local ports to your Sprite for direct access:
59+
Try these examples:
7660

7761
<Tabs>
7862
<TabItem label="CLI">
@@ -115,94 +99,30 @@ defer func() {
11599
</TabItem>
116100
</Tabs>
117101

118-
### Port Mapping
119-
120-
You can map local ports to different remote ports:
121-
122-
```go
123-
sessions, err := client.ProxyPorts(ctx, "my-sprite", []sprites.PortMapping{
124-
{LocalPort: 3000, RemotePort: 8080}, // localhost:3000 -> sprite:8080
125-
{LocalPort: 5433, RemotePort: 5432}, // localhost:5433 -> sprite:5432
126-
})
127-
```
128-
129-
### Forwarding to Specific Hosts
130-
131-
For services bound to specific interfaces:
132-
133-
```go
134-
sessions, err := client.ProxyPorts(ctx, "my-sprite", []sprites.PortMapping{
135-
{LocalPort: 5432, RemotePort: 5432, RemoteHost: "10.0.0.1"},
136-
})
137-
```
138-
139-
## Port Notifications
140-
141-
Get notified when services start listening on ports inside your Sprite:
142-
143-
<Tabs>
144-
<TabItem label="JavaScript">
145-
```javascript
146-
const cmd = sprite.spawn('npm', ['run', 'dev']);
147-
148-
cmd.on('message', (msg) => {
149-
if (msg.type === 'port_opened') {
150-
console.log(`Port ${msg.port} opened on ${msg.address} by PID ${msg.pid}`);
151-
152-
// Auto-open browser
153-
const url = `http://localhost:${msg.port}`;
154-
exec(`open ${url}`); // macOS
155-
} else if (msg.type === 'port_closed') {
156-
console.log(`Port ${msg.port} closed`);
157-
}
158-
});
159-
160-
await cmd.wait();
161-
```
162-
</TabItem>
102+
Port forwarding works for TCP services — web servers, databases, message brokers, whatever. It's just sockets.
163103

164-
<TabItem label="Go">
165-
```go
166-
cmd := sprite.Command("npm", "run", "dev")
167-
cmd.TextMessageHandler = func(data []byte) {
168-
var notification sprites.PortNotificationMessage
169-
if err := json.Unmarshal(data, &notification); err != nil {
170-
return
171-
}
104+
## Real-World Examples
172105

173-
switch notification.Type {
174-
case "port_opened":
175-
fmt.Printf("Port %d opened on %s by PID %d\n",
176-
notification.Port, notification.Address, notification.PID)
106+
### Starting a Web Server
177107

178-
// Could auto-forward port
179-
session, _ := client.ProxyPort(ctx, "my-sprite",
180-
notification.Port, notification.Port)
108+
Run a web server and access it via the Sprite URL:
181109

182-
case "port_closed":
183-
fmt.Printf("Port %d closed\n", notification.Port)
184-
}
185-
}
186-
cmd.Run()
187-
```
188-
</TabItem>
189-
</Tabs>
110+
```bash
111+
# Start a simple HTTP server
112+
sprite exec -detachable "python -m http.server 8080"
190113

191-
### Port Notification Structure
114+
# Get the URL
115+
sprite url
116+
# Output: https://my-sprite-abc123.sprites.dev
192117

193-
```typescript
194-
interface PortNotification {
195-
type: 'port_opened' | 'port_closed';
196-
port: number;
197-
address: string;
198-
pid: number;
199-
}
118+
# Access via browser or curl (after making public)
119+
curl https://my-sprite-abc123.sprites.dev:8080/
200120
```
201121

202-
## Common Patterns
203-
204122
### Development Server
205123

124+
Let's say you've got a frontend or backend dev server that watches files and hot reloads.
125+
206126
```bash
207127
# Start dev server in detachable session
208128
sprite exec -detachable "cd /home/sprite/app && npm run dev"
@@ -213,9 +133,12 @@ sprite proxy 3000
213133
# Open in browser
214134
open http://localhost:3000
215135
```
136+
If your server starts dynamically (e.g. via a watcher), Sprites can emit events when a process binds a port. You can hook into those if you want to script around startup behavior.
216137

217138
### Database Access
218139

140+
Running a database inside a Sprite is weirdly nice. You can spin up Postgres, forward its port, and connect with your usual tools:
141+
219142
```bash
220143
# Start PostgreSQL (if installed)
221144
sprite exec -detachable "pg_ctl start"
@@ -229,6 +152,8 @@ psql -h localhost -p 5432 -U postgres
229152

230153
### Multiple Services
231154

155+
Sprites can run multiple processes. You can forward all the ports you care about:
156+
232157
```bash
233158
# Start multiple services
234159
sprite exec -detachable "cd /home/sprite/api && npm start" # Port 3000
@@ -239,80 +164,46 @@ sprite exec -detachable "redis-server" # Port 6379
239164
sprite proxy 3000 3001 6379
240165
```
241166

242-
## Network Environment
243-
244-
### Default Configuration
167+
## Network Behavior
245168

246169
Sprites have full network access by default:
247170

248-
- **Outbound**: All protocols and ports
249-
- **Inbound**: Via Sprite URL or port forwarding
250-
- **DNS**: Standard resolution working
251-
252-
### Making HTTP Requests
253-
254-
```bash
255-
# From inside the sprite
256-
sprite exec "curl https://api.example.com/data"
257-
sprite exec "wget https://files.example.com/archive.tar.gz"
258-
```
259-
260-
### Installing Network Tools
171+
- **Outbound**: All protocols and ports. You can fetch packages, call APIs and more
172+
- **Inbound**: Only via Sprite URL or port forwarding
173+
- **DNS**: Standard resolution works
261174

262-
The default environment includes common tools. Install additional ones as needed:
175+
The default environment includes common network tools, and you can install additional ones as needed. You can run tools like `netcat`, `curl`, or `nmap` or `wget`. Nothing is artificially restricted and this isn't a locked-down environment.
263176

177+
Example network tool installation:
264178
```bash
265179
sprite exec "apt-get update && apt-get install -y nmap netcat"
266180
```
267181

268-
## Security Considerations
269-
270-
### Public URLs
271-
272-
When making a Sprite URL public:
273-
274-
1. **Only expose what you need** - Run services on specific ports
275-
2. **Use application-level auth** - Implement your own authentication
276-
3. **Monitor access** - Check logs for unexpected traffic
277-
4. **Temporary exposure** - Make public only when needed
278-
279-
### Firewall Rules
280-
281-
Services inside your Sprite can bind to any port. Control access through:
282-
283-
- URL authentication settings
284-
- Application-level security
285-
- Not exposing sensitive services
286-
287182
## Troubleshooting
288183

289-
### Port Not Accessible
184+
**Not seeing your app on the URL?** Make sure it's listening on `0.0.0.0`, not `localhost`. The router can't see loopback-only services.
290185

291-
```bash
292-
# Check if service is running
293-
sprite exec "ss -tlnp"
186+
**Forwarded port not responding?** Check the app is actually running, and that you forwarded the right port. Use `sprite ps` to see running processes.
294187

295-
# Check if service is bound to correct interface
296-
sprite exec "netstat -tlnp"
188+
**Getting a 403 on your Sprite URL?** It's probably set to private. Make it public with `sprite url --public` or authenticate with a token.
297189

298-
# Services should bind to 0.0.0.0, not 127.0.0.1
299-
```
190+
**Dynamic apps not ready right away?** If your service binds ports after startup, you can use port open events from the SDK to wait for readiness.
191+
192+
## Security Notes
300193

301-
### Connection Refused
194+
By default, your Sprite isn't publicly accessible. That's on purpose. You control what gets exposed — either by forwarding a port or making the Sprite's URL public.
302195

303-
1. Verify the service is running
304-
2. Check the port number
305-
3. Ensure service binds to `0.0.0.0` not just `localhost`
306-
4. Verify port forwarding is active
196+
A few things to keep in mind:
307197

308-
### Slow Connections
198+
- **Only expose what you actually need** - Run services on specific ports
199+
- **Use app-level auth** - If you're building anything real, implement your own authentication
200+
- **Forwarded ports are reachable from your machine** — Not the wider Internet.
201+
- **Temporary exposure** - Make public only when needed.
309202

310-
- Check if Sprite is hibernated (first request wakes it)
311-
- Consider pre-warming for latency-sensitive applications
312-
- Use regions closer to your users
203+
We don't add firewall rules or block inbound traffic to forwarded ports, but we also don't auto-protect what you expose. You're in control, which is powerful — and dangerous, if you're not paying attention. Keep it minimal and secure.
313204

314205
## Related Documentation
315206

316-
- [Sprites Guide](/sprites) - Comprehensive guide
317-
- [CLI Commands](/cli/commands) - Port forwarding commands
318-
- [Configuration](/reference/configuration) - Network settings
207+
- [Working with Sprites](/working-with-sprites) - Beyond the basics guide to using Sprites
208+
- [CLI Commands](/cli/commands) - Command reference
209+
- [Configuration](/reference/configuration) - Network settings

0 commit comments

Comments
 (0)