This Netlify Edge Function creates dynamic redirects to Stackblitz with specific versions of the Handsontable library based on query parameters. It fetches example code from the GitHub repository and creates a Stackblitz project with the specified Handsontable version.
The main purpose is to create dynamic redirects to Stackblitz from the examples folder using particular versions of the Handsontable library based on query parameters. This allows users to quickly spin up interactive examples with specific Handsontable versions for testing and demonstration purposes.
- Parameter Processing: The function extracts query parameters to determine which example to load and which Handsontable version to use
- Version Resolution: It resolves the Handsontable version using GitHub API and NPM registry
- File Fetching: It fetches example files from the GitHub repository
- Package Configuration: It updates the package.json with the specified Handsontable version
- Stackblitz Redirect: It creates an HTML form that automatically submits to Stackblitz with the configured project
| Parameter | Type | Required | Description |
|---|---|---|---|
example-dir |
string | ✅ Yes | Directory name of the example to load (e.g., "example1") |
example-branch |
string | ❌ No | Git branch to fetch example from (defaults to main/master) |
handsontable-branch |
string | ❌ No | Handsontable repository branch to use for version resolution |
handsontable-sha |
string | ❌ No | Specific commit SHA to use for version resolution |
handsontable-version |
string | ❌ No | Specific NPM version (e.g., "16.0.0") |
The function resolves the Handsontable version in the following order:
handsontable-version- Direct NPM version (highest priority)handsontable-branch- Finds NPM version matching the branch's commit SHAhandsontable-sha- Finds NPM version matching the specific commit SHAlatest- Default fallback (lowest priority)
https://your-domain.netlify.app/stackblitz?example-dir=example1
https://your-domain.netlify.app/stackblitz?example-dir=example1&handsontable-version=16.0.0
https://your-domain.netlify.app/stackblitz?example-dir=example1&handsontable-branch=develop
https://your-domain.netlify.app/stackblitz?example-dir=example1&example-branch=feature-branch&handsontable-version=15.0.0
- GET
/stackblitz- Main endpoint for Stackblitz redirects - OPTIONS
/stackblitz- CORS preflight handling
- Content-Type:
text/html - Body: HTML form that auto-submits to Stackblitz
- Status:
200
- Content-Type:
application/json - Body:
{"error": "error message"} - Status:
500
| Variable | Description | Required |
|---|---|---|
GITHUB_TOKEN |
GitHub API token for repository access | ✅ Yes |
The function includes CORS headers to support cross-origin requests:
Access-Control-Allow-Origin: *Access-Control-Allow-Methods: GET, POST, OPTIONSAccess-Control-Allow-Headers: Content-Type
edge/
├── netlify/
│ └── edge-functions/
│ └── stackblitz.mts # Main edge function
├── src/
│ ├── index.ts # HTML utilities
│ ├── github.ts # GitHub API integration
│ └── version.ts # Version resolution logic
├── netlify.toml # Netlify configuration
└── readme.md # This documentation
- @octokit/rest - GitHub API client
- Deno - Runtime environment for edge functions
The function handles various error scenarios:
- Missing required parameters
- GitHub API failures
- Invalid repository paths
- Network timeouts
- Invalid version specifications
All errors are returned as JSON with appropriate HTTP status codes.
- GitHub token is required for private repository access
- Public repositories could be accessed without tokens (future optimization)
- Input validation prevents path traversal attacks
- CORS headers are properly configured
- Files are fetched in parallel using Promise.all
- GitHub API calls are optimized to minimize requests
- Version resolution is cached where possible
- Edge function provides low-latency responses