Skip to content

You get a page from your VM embedded in your own site, behind a link for one viewer. A viewer without the link gets 401.

  • A VM. Create one from your terminal and keep its id.
  • An organization key.
  • An app that listens on port 3000 in the VM. This guide starts a placeholder page.

Set these once in your terminal:

Terminal window
export SI_API_KEY=<your-organization-key>
VM=<your-vm-id>

The app starts as a background job. The request ends after the job starts, and the server keeps running.

Terminal window
curl -sS -H "Authorization: Bearer $SI_API_KEY" --data-binary 'mkdir -p /home/user/site && echo hello > /home/user/site/index.html && cd /home/user/site && python3 -m http.server 3000' "https://$VM.slashinfra.dev/usr/bin/job?arg=-q"
Output
3

Then open the port to links. An authenticated port accepts members and link holders.

Terminal window
curl -sS -X PUT -H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" -d '{"access":"authenticated"}' "https://api.slashinfra.com/svms/$VM/ports/3000"
Output
{"access":"authenticated","port":3000,...}

A link is a credential. Anyone who holds it can open the preview, so give it to one viewer. The link lasts one hour unless you set ttl_s, up to the plan’s maximum of 30 days.

Terminal window
curl -sS -X POST -H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" -d '{"ttl_s":3600}' "https://api.slashinfra.com/svms/$VM/ports/3000/url"
Output
{"url":"https://3000-<id>.slashinfra.dev/?si_access=...","expires_at":...}

Put the url from step 2 in an iframe on your page.

<iframe src="https://3000-<id>.slashinfra.dev/?si_access=..."></iframe>

Some browsers block cookies in embedded pages. If the frame stays empty, open the link in its own tab.

A viewer who does not hold the link sends a request without it. The port answers 401.

Terminal window
curl -sS -o /dev/null -w "%{http_code}\n" "https://3000-$VM.slashinfra.dev/"
Output
401

The iframe shows hello. The request from step 4 returns 401, so the page is open only to viewers who hold the link.

Symptom Cause Fix
401 in the frame The link expired, or the port was rotated or closed. Make a new link in step 2.
409 port_closed when you make a link The port is closed. Open it in step 1.
503 with nothing listens on port 3000 in this computer The server is not running. Read the job’s log in /var/log/jobs/, then start the server again.

Scroll horizontally to see all columns.

Terminal window
curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE -H "Authorization: Bearer $SI_API_KEY" "https://api.slashinfra.com/svms/$VM/ports/3000"
Output
204
  • Background work: run a job that outlives the request.
  • Grants: a link that admits one method and path, such as reading files, instead of the app.
  • Web addresses: the access states of a port and how a preview reaches your app.