Build a video sharing app with StreamGate
StreamGate is a self-hosted video sharing web app built with Next.js and powered by FastPix. It lets users upload videos or record their screen and camera in the browser, then share a permanent link within seconds. No database is required.
Live demo: streamgate.dev
Overview
StreamGate implements a complete video upload and playback workflow using FastPix APIs. Key capabilities include:
- Drag-and-drop file uploading with a progress bar
- In-browser screen and camera recording through the MediaRecorder API
- Adaptive HLS playback delivered over FastPix’s global CDN with an adaptive bitrate ladder
- Webhook event handling for asset lifecycle events
- Permanent shareable URLs for every uploaded video
Before you begin
System requirements
Get your FastPix API credentials
FastPix APIs use HTTP Basic Auth. Your Access Token ID is the username; your Secret Key is the password.
To generate credentials:
- Log in to the FastPix Dashboard.
- Go to Manage → Access Tokens.
- Copy your Access Token ID and Secret Key.
For detailed steps, see Authentication with Basic Auth.
Set up StreamGate
Clone the repository and install dependencies
Configure environment variables
Create a .env.local file in the project root:
Add the following variables:
WARNING:
Never commit
.env.localto version control. The file is already listed in.gitignore.
For a full description of each variable, see Environment variables reference.
Start the development server
Open http://localhost:3000 in your browser.
Routes and API endpoints
Upload
Playback
Recording
Webhooks
Integrate StreamGate into an existing app
You don’t need to run StreamGate as a standalone project. You can copy individual parts into your own codebase.
Option A: Copy the API routes (backend only)
Copy the following files into your Next.js project for server-side FastPix integration:
Install the FastPix Node SDK:
Then call the routes from your existing frontend:
Option B: Copy the React components
Copy these ready-made components into your Next.js or React project:
<Uploader /> — drag-and-drop file upload with a progress bar:
<Player /> — FastPix HLS player web component:
<Recorder /> — in-browser screen and camera recorder:
Install the required dependencies:
Option C: Use the FastPix Node SDK directly
For non-Next.js backends, use the FastPix Node SDK without any of the StreamGate files:
For the full SDK reference, see the FastPix API reference.
Webhooks
StreamGate verifies incoming FastPix webhook payloads using HMAC-SHA256. To enable verification, set the FASTPIX_WEBHOOK_SECRET environment variable.
Register your endpoint
In the FastPix Dashboard, go to Manage → Webhooks and add:
Supported events
Note: If
FASTPIX_WEBHOOK_SECRETis not set, signature verification is skipped. This is acceptable for local development but not recommended in production.
Error handling
All API routes return JSON error responses with an error field and an HTTP status code.
Example: handling an upload error
FastPix API errors are logged to the server console with the full status code, response body, and headers.
Deploy to Cloudflare Pages
Cloudflare Pages is the recommended deployment target for StreamGate.
Install the adapter and Wrangler CLI
Create wrangler.toml
In the project root, create a wrangler.toml file with the following content:
NOTE:
The
nodejs_compatflag is required. StreamGate uses the FastPix SDK and the Node.jscryptomodule for webhook signature verification.
Add build scripts to package.json
Deploy
Set environment variables
- Open the Cloudflare Dashboard.
- Go to Pages → your project → Settings → Environment variables.
- Add all four environment variables for both the Production and Preview environments.
- Set
NEXT_PUBLIC_BASE_URLto your production domain, for examplehttps://streamgate.pages.dev.