You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/sandbox/concepts/preview-urls.mdx
+33-47Lines changed: 33 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,62 +5,54 @@ sidebar:
5
5
order: 5
6
6
---
7
7
8
-
Preview URLs provide public access to services running inside sandboxes. When you expose a port, you get a unique HTTPS URL that proxies requests to your service.
8
+
:::note[Production requires custom domain]
9
+
Preview URLs work in local development without configuration. For production, you need a custom domain with wildcard DNS routing. See [Production Deployment](/sandbox/guides/production-deployment/).
10
+
:::
11
+
12
+
Preview URLs provide public HTTPS access to services running inside sandboxes. When you expose a port, you get a unique URL that proxies requests to your service.
Your sandbox is now deployed and can execute code in isolated containers.
155
+
156
+
:::note[Preview URLs require custom domain]
157
+
If you plan to expose ports from sandboxes (using `exposePort()` for preview URLs), you will need to set up a custom domain with wildcard DNS routing. The `.workers.dev` domain does not support the subdomain patterns required for preview URLs. See [Production Deployment](/sandbox/guides/production-deployment/) when you are ready to expose services.
158
+
:::
155
159
156
160
## Understanding the configuration
157
161
@@ -201,4 +205,5 @@ Now that you have a working sandbox, explore more capabilities:
201
205
-[Execute commands](/sandbox/guides/execute-commands/) - Run shell commands and stream output
202
206
-[Manage files](/sandbox/guides/manage-files/) - Work with files and directories
203
207
-[Expose services](/sandbox/guides/expose-services/) - Get public URLs for services running in your sandbox
208
+
-[Production Deployment](/sandbox/guides/production-deployment/) - Set up custom domains for preview URLs
204
209
-[API reference](/sandbox/api/) - Complete API documentation
Copy file name to clipboardExpand all lines: src/content/docs/sandbox/guides/expose-services.mdx
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,10 @@ sidebar:
7
7
8
8
import { TypeScriptExample } from"~/components";
9
9
10
+
:::note[Production requires custom domain]
11
+
Preview URLs require a custom domain with wildcard DNS routing in production. See [Production Deployment](/sandbox/guides/production-deployment/) for setup instructions.
12
+
:::
13
+
10
14
This guide shows you how to expose services running in your sandbox to the internet via preview URLs.
Custom domain setup is ONLY needed if you use `exposePort()` to expose services from sandboxes. If your application does not expose ports, you can deploy to `.workers.dev` without this configuration.
12
+
:::
13
+
14
+
Deploy your Sandbox SDK application to production with preview URL support. Preview URLs require wildcard DNS routing because they generate unique subdomains for each exposed port: `https://8080-abc123.yourdomain.com`.
15
+
16
+
The `.workers.dev` domain does not support wildcard subdomains, so production deployments that use preview URLs need a custom domain.
In the Cloudflare dashboard, go to your domain and create an A record:
29
+
30
+
-**Type**: A
31
+
-**Name**: * (wildcard)
32
+
-**IPv4 address**: 192.0.2.0
33
+
-**Proxy status**: Proxied (orange cloud)
34
+
35
+
This routes all subdomains through Cloudflare's proxy. The IP address `192.0.2.0` is a documentation address (RFC 5737) that Cloudflare recognizes when proxied.
36
+
37
+
### Configure Worker Routes
38
+
39
+
Add a wildcard route to your Wrangler configuration:
40
+
41
+
<WranglerConfig>
42
+
```toml
43
+
name = "my-sandbox-app"
44
+
main = "src/index.ts"
45
+
compatibility_date = "$today"
46
+
47
+
[[routes]]
48
+
pattern = "*.yourdomain.com/*"
49
+
zone_name = "yourdomain.com"
50
+
```
51
+
</WranglerConfig>
52
+
53
+
Replace `yourdomain.com` with your actual domain. This routes all subdomain requests to your Worker and enables Cloudflare to provision SSL certificates automatically.
Visit the URL in your browser to confirm your service is accessible.
77
+
78
+
## Troubleshooting
79
+
80
+
-**CustomDomainRequiredError**: Verify your Worker is not deployed to `.workers.dev` and that the wildcard DNS record and route are configured correctly.
81
+
-**SSL/TLS errors**: Wait a few minutes for certificate provisioning. Verify the DNS record is proxied and SSL/TLS mode is set to "Full" or "Full (strict)" in your dashboard.
82
+
-**Preview URL not resolving**: Confirm the wildcard DNS record exists and is proxied. Wait 30-60 seconds for DNS propagation.
83
+
-**Port not accessible**: Ensure your service binds to `0.0.0.0` (not `localhost`) and that `proxyToSandbox()` is called first in your Worker's fetch handler.
84
+
85
+
For detailed troubleshooting, see the [Workers routing documentation](/workers/configuration/routing/).
86
+
87
+
## Related Resources
88
+
89
+
-[Preview URLs](/sandbox/concepts/preview-urls/) - How preview URLs work
90
+
-[Expose Services](/sandbox/guides/expose-services/) - Patterns for exposing ports
0 commit comments