### Build FastEdge JavaScript Example Source: https://github.com/g-core/fastedge-examples/blob/main/javascript/README.md Clone the SDK repository, navigate to the desired example directory, and run npm install and npm run build to produce the WASM file. ```sh git clone git@github.com:G-Core/FastEdge-sdk-js.git cd FastEdge-sdk-js/examples/ npm install npm run build ``` -------------------------------- ### Build AssemblyScript Example Source: https://github.com/g-core/fastedge-examples/blob/main/assemblyscript/README.md Clone the SDK repository, navigate to the example directory, install dependencies, and build the AssemblyScript code. This process generates a .wasm file for release and a debug version. ```sh git clone git@github.com:G-Core/proxy-wasm-sdk-as.git cd proxy-wasm-sdk-as/examples/ pnpm install pnpm run asbuild ``` -------------------------------- ### Environment Configuration Example Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Example of setting environment variables for application configuration during deployment. These can be accessed by the SDK. ```yaml env: | LOG_LEVEL=debug API_URL=https://api.example.com/ FEATURE_FLAG_NEW_UI=true ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Installs all project dependencies listed in `package.json`. This command should be run before building or developing the application. ```bash npm ci ``` -------------------------------- ### Clone FastEdge Examples Repository Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md Clone the repository to access example configurations and workflows. Navigate into the single-app workflows directory. ```bash git clone https://github.com/gcore-github-actions/fastedge-examples.git cd fastedge-examples/github-actions/single-app-workflows ``` -------------------------------- ### Build Rust Example with Cargo Source: https://github.com/g-core/fastedge-examples/blob/main/rust/README.md Clone the SDK repository, navigate to the example directory, and build the release version of the Wasm module using Cargo. ```sh git clone https://github.com/G-Core/FastEdge-sdk-rust.git cd FastEdge-sdk-rust/examples/ cargo build --release ``` -------------------------------- ### Install JavaScript Dependencies Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Commands to install project dependencies using npm. `npm ci` is recommended for CI environments to ensure exact version installs. ```bash npm ci # Install exact versions from package-lock.json ``` ```bash npm install # Update to latest compatible versions ``` -------------------------------- ### HTTP Response Example (Config/Secrets) Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Demonstrates a JSON response containing application configuration, environment details, and secrets. ```json HTTP/1.1 200 OK Content-Type: application/json x-custom-header: some-test-value { "url": "https://app.example.com/", "env": { "environment": "production", "apiUrl": "https://api.example.com/v1/" }, "secrets": { "apiKey": "secret-key-value", "apiSessionToken": "session-token-slot-10" } } ``` -------------------------------- ### Install Dependencies and Build Application Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Standard npm commands for managing project dependencies and executing build scripts. `npm ci` installs dependencies, while `npm run build:` compiles the specified application. ```bash npm ci # Install dependencies ``` ```bash npm run build:first-app # Build first-app to dist/first-app.wasm ``` ```bash npm run build:second-app # Build second-app to dist/second-app.wasm ``` -------------------------------- ### Build Command for First App Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Builds the JavaScript application for deployment. Ensure npm is installed and dependencies are managed. ```bash npm run build:first-app ``` -------------------------------- ### HTTP Request Example Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Illustrates a typical HTTP GET request to an API endpoint. ```http GET /api/users?id=123 HTTP/1.1 Host: app.example.com ``` -------------------------------- ### HTTP Request Example (Config/Secrets) Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md A basic HTTP GET request to the root path. ```http GET / HTTP/1.1 Host: app.example.com ``` -------------------------------- ### Build AssemblyScript Projects Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Commands to install dependencies and build AssemblyScript projects using pnpm and asbuild. ```bash pnpm install ``` ```bash pnpm run asbuild ``` -------------------------------- ### Action Input: Environment Variables Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Example of providing multi-line environment variables in a key=value format. Each pair should be on a new line. ```yaml env: | environment=production api-url=https://api.example.com/v1/ log-level=debug ``` -------------------------------- ### JavaScript Key-Value Store Access Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Example demonstrating how to interact with a Key-Value store using the FastEdge JavaScript SDK. Supports getting and putting data with optional TTL. ```javascript import { KvStore } from "fastedge::kv"; const kv = new KvStore(); const value = await kv.get("my-key"); await kv.put("my-key", "my-value", {ttl: 3600}); ``` -------------------------------- ### Environment Variable Examples Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Examples of environment variables. Keys should be alphanumeric and hyphens, and values are treated as strings without type coercion. ```env environment=production api-url=https://api.example.com/v1/ log-level=debug feature-flag-new-ui=true database-host=db.example.com ``` -------------------------------- ### Build Command for Second App Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Builds the second JavaScript application. Ensure npm is installed and dependencies are managed. ```bash npm run build:second-app ``` -------------------------------- ### Node.js Package Installation Commands Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/05-package-configuration.md Common npm commands for installing project dependencies. 'npm ci' is recommended for CI/CD environments to ensure exact dependency versions. ```bash # Install exact versions from package-lock.json (recommended for CI/CD) npm ci ``` ```bash # Update to latest compatible versions npm install ``` ```bash # Install specific version npm install @gcoredev/fastedge-sdk-js@2.5.1 ``` -------------------------------- ### HTTP Response Example (Echo) Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Shows a successful HTTP response with a plain text body echoing the request URL. ```http HTTP/1.1 200 OK Content-Type: text/plain You made a request to https://app.example.com/api/users?id=123 ``` -------------------------------- ### Action Input: API Key Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Example of how to provide an API key as a string input. It is typically retrieved from secrets. ```yaml api_key: ${{ secrets.GCORE_API_KEY }} ``` -------------------------------- ### Simple FastEdge Application Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md An example of a basic FastEdge application using the 'fetch' event handler to respond to requests. It demonstrates a simple 'Hello World' style response. ```javascript async function eventHandler(event) { const request = event.request; return new Response(`Hello from ${request.url}`); } addEventListener("fetch", (event) => { event.respondWith(eventHandler(event)); }); ``` -------------------------------- ### Secret Examples Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Examples of secrets. Keys are alphanumeric with hyphens, and values are any string. Secrets are retrieved at runtime and masked in logs. ```env api-key=my-secret-key-value database-password=secure-password-123 auth-token=jwt-token-value ``` -------------------------------- ### Action Input: Response Headers Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Example of specifying response headers using a multi-line string in Header-Name=value format. Standard HTTP header names are expected. ```yaml rsp_headers: | Content-Type=application/json Cache-Control=no-cache X-Custom-Header=custom-value ``` -------------------------------- ### Action Input: Application Name Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Example of providing a unique application name. The name must be alphanumeric with hyphens only. ```yaml app_name: "first-app" ``` -------------------------------- ### Action Input: Secrets Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Example of mapping secret keys to their corresponding IDs obtained from previous steps. Keys must match SDK secret names. ```yaml secrets: | api-key=${{ steps.create-api-key-secret.outputs.secret_id }} api-session-token=${{ steps.create-api-session-token-secret.outputs.secret_id }} ``` -------------------------------- ### JavaScript HTTP Request Example Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Example of making an outbound HTTP POST request from the edge using the FastEdge JavaScript SDK. Includes setting headers and request body. ```javascript const response = await fetch("https://api.example.com/data", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key: "value" }) }); ``` -------------------------------- ### Secrets Management Example Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Example of defining secrets for secure retrieval during deployment. These are sensitive values used by the application. ```yaml secrets: | database-password=secret-id-123 api-key=secret-id-456 ``` -------------------------------- ### Compile JavaScript to WebAssembly with fastedge-build Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Use this command to compile a JavaScript source file into a WebAssembly binary. Ensure Node.js 22.x or later and the `@gcoredev/fastedge-sdk-js` package are installed. ```bash npx fastedge-build ./src/first-app/index.js ./dist/first-app.wasm ``` -------------------------------- ### Action Input: Wasm File Path Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Example of specifying the path to a WebAssembly file. The path is relative to the repository root. ```yaml wasm_file: dist/first-app.wasm ``` -------------------------------- ### Deploy First App Workflow Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/05-package-configuration.md This workflow builds and deploys the first application. It triggers on pushes to the 'single-app-repo' branch if specific paths change. Ensure Node.js 22.x is set up and npm dependencies are installed. ```yaml name: Build & Deploy First Application on: push: branches: - single-app-repo paths: - "src/first-app/**" - ".github/workflows/deploy-first-app.yaml" jobs: build_and_deploy_first_app: name: Build binaries runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js latest uses: actions/setup-node@v4 with: node-version: 22.x - name: Install dependencies shell: bash run: | npm ci - name: Build Binary shell: bash run: | npm run build:first-app - name: Deploy First App to FastEdge uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: dist/first-app.wasm app_name: "first-app" ``` -------------------------------- ### Setup Node.js Version in Workflow Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/05-package-configuration.md Configure the Node.js version for your workflow using the `actions/setup-node` action. It's recommended to use LTS versions and update annually. ```yaml - name: Setup Node.js latest uses: actions/setup-node@v4 with: node-version: 22.x # Change this for newer version ``` -------------------------------- ### Build and Deploy Second Application Workflow Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/03-github-actions-deployment.md This YAML workflow automates the build and deployment of the 'second-app' to FastEdge. It checks out code, sets up Node.js, installs dependencies, builds the application binary, creates necessary secrets (API key and session token), and finally deploys the application. It triggers on pushes to the 'single-app-repo' branch affecting the app's source code or the workflow file itself. ```yaml name: Build & Deploy Second Application on: push: branches: - single-app-repo paths: - "src/second-app/**" - ".github/workflows/deploy-second-app.yaml" jobs: build_and_deploy_second_app: name: Build binaries runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js latest uses: actions/setup-node@v4 with: node-version: 22.x - name: Install dependencies shell: bash run: | npm ci - name: Build Binary shell: bash run: | npm run build:second-app - name: Create API Key Secret id: create-api-key-secret uses: gcore-github-actions/fastedge/secrets@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} secret_name: "my-backend-api-key" secret_value: "${{ secrets.BACKEND_API_KEY }}" - name: Create Api Session Token Secret id: create-api-session-token-secret uses: gcore-github-actions/fastedge/secrets@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} secret_name: "my-api-session-token" secret_slots: "${{ secrets.API_SESSION_TOKEN }}" - name: Deploy Second App to FastEdge uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: dist/second-app.wasm app_name: "second-app" env: | environment=production api-url=https://api.example.com/v1/ rsp_headers: | Content-Type=application/json secrets: | api-key=${{ steps.create-api-key-secret.outputs.secret_id }} api-session-token=${{ steps.create-api-session-token-secret.outputs.secret_id }} ``` -------------------------------- ### Download Release Action Usage in Workflow Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/05-package-configuration.md Example of how to use the 'download-release' composite action in a GitHub Actions workflow. It shows how to specify the release version and output directory. ```yaml - name: Download Latest Release Assets id: download-release uses: ./.github/download-release with: release_version: "latest" github_token: ${{ secrets.GITHUB_TOKEN }} build_directory: ${{ env.CURRENT_RELEASE_DIR }} ``` -------------------------------- ### Build Javascript Action Usage in Workflow Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/05-package-configuration.md Example of how to use the 'build-javascript' composite action within a GitHub Actions workflow. It demonstrates passing required and optional inputs. ```yaml - name: Build JS First App uses: ./.github/build-javascript with: git_diff_directory: src/first-app wasm_filepath: dist wasm_filename: first-app.wasm build_command: npm run build:first-app current_release_directory: ${{ env.CURRENT_RELEASE_DIR }} previous_release_directory: ${{ env.PREVIOUS_RELEASE_DIR }} ``` -------------------------------- ### Accessing and Checking Headers Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Provides examples of using the Headers interface methods to retrieve a specific header value and check for the existence of another. ```javascript const headers = request.headers; const contentType = headers.get("Content-Type"); const hasAuth = headers.has("Authorization"); ``` -------------------------------- ### Advanced FastEdge Application with Environment and Secrets Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md This example demonstrates an advanced FastEdge application that utilizes `fastedge::env` to access environment variables and `fastedge::secret` to retrieve secrets like an API key. ```javascript import { getEnv } from "fastedge::env"; import { getSecret } from "fastedge::secret"; async function eventHandler(event) { const request = event.request; return new Response(JSON.stringify({ url: request.url, env: getEnv("environment"), secret: getSecret("api-key") })); } addEventListener("fetch", (event) => { event.respondWith(eventHandler(event)); }); ``` -------------------------------- ### GitHub Actions Input Schema Example Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Define inputs for a GitHub Actions workflow, specifying their descriptions, whether they are required, and optional default values. Input names should be lowercase with underscores. ```yaml inputs: wasm_filepath: description: "filepath to built wasm" required: true working_directory: description: "where to execute commands" required: false default: "." ``` -------------------------------- ### Manage Secrets with GitHub Actions Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md Ensure secrets are created and their IDs are correctly referenced before deploying your application. This example shows how to create a secret and use its output ID in the deploy-app step. ```yaml - name: Create API Key Secret id: create-api-key-secret # Save step ID uses: gcore-github-actions/fastedge/secrets@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} secret_name: "my-backend-api-key" secret_value: "${{ secrets.BACKEND_API_KEY }}" - name: Deploy App uses: gcore-github-actions/fastedge/deploy-app@v1 with: secrets: | api-key=${{ steps.create-api-key-secret.outputs.secret_id }} # ↑ Must match step ID above ``` -------------------------------- ### Single Application Deployment Flow Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/01-project-overview.md Illustrates the direct build-and-deploy flow for a single application triggered by code pushes. Suitable for simple projects. ```text Code Push → GitHub Actions Trigger → npm ci → npm run build → Deploy to FastEdge ``` -------------------------------- ### Create a Response object Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Demonstrates the constructor for creating a Response object, including setting custom headers. ```javascript new Response(body, { headers: { "Header-Name": "value" } }) ``` -------------------------------- ### Build a Specific Application Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Compiles a specific application to WebAssembly using the defined npm script. Replace `` with the actual name of your application. ```bash npm run build: ``` -------------------------------- ### Application: First App - Request Echo Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md This application handles all incoming HTTP requests, regardless of method or path, and responds with the requested URL. It demonstrates basic request echoing. ```APIDOC ## Any / ### Description Handles all incoming HTTP requests and echoes the requested URL back to the client. ### Method Any (GET, POST, etc.) ### Endpoint All routes (no fixed routing) ### Response #### Success Response (200) - **Content-Type**: text/plain - **Body**: `You made a request to ` ### Request Example ```http GET /api/users?id=123 HTTP/1.1 Host: app.example.com ``` ### Response Example ``` HTTP/1.1 200 OK Content-Type: text/plain You made a request to https://app.example.com/api/users?id=123 ``` ``` -------------------------------- ### Create API Key with Minimal Permissions Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md When creating API keys, ensure they have only the necessary permissions, such as 'FastEdge Deployments', and avoid granting admin or full API access. ```bash # Create API key with minimal permissions # - Only "FastEdge Deployments" permission # - Not admin or full API access ``` -------------------------------- ### Build JavaScript to WebAssembly Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Command to compile a JavaScript entry point file into a WebAssembly binary using fastedge-build. ```bash npx fastedge-build ./src/app.js ./dist/app.wasm ``` -------------------------------- ### Access request properties Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Example of accessing properties of the incoming request object within a fetch event handler. ```javascript const request = event.request; request.url // Full request URL request.method // HTTP method (GET, POST, etc.) request.headers // Headers object request.body // Request body (if applicable) ``` -------------------------------- ### API_SESSION_TOKEN Format Example Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md This JSON structure defines the format for the API_SESSION_TOKEN secret, which includes session slot configurations. It should be pasted as a single line in GitHub secrets. ```json [ {"slot": 0, "value": "current-session-secret"}, {"slot": 10, "value": "next-session-secret"} ] ``` ```json [{"slot": 0, "value": "current-session-secret"}, {"slot": 10, "value": "next-session-secret"}] ``` -------------------------------- ### Get Secret Value by Name Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Retrieves a secret value using its identifier. The secret must be pre-created and linked during deployment. Returns `undefined` if the secret does not exist. ```javascript import { getSecret } from "fastedge::secret"; const apiKey = getSecret("api-key"); ``` -------------------------------- ### Environment-Specific Deployment with Separate Workflows Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md Demonstrates how to use separate GitHub Actions workflows for production and staging deployments based on Git tags or branches. ```yaml # deploy-prod.yaml on: push: tags: - "v*.*.*" # deploy-staging.yaml on: push: branches: - develop ``` -------------------------------- ### Deploy Second App Workflow Configuration Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/05-package-configuration.md This workflow deploys the second application, similar to the first but with specific trigger paths for 'src/second-app/**' and a different build command. It also includes steps for creating and utilizing secrets for API keys and session tokens. ```yaml paths: - "src/second-app/**" - ".github/workflows/deploy-second-app.yaml" ``` ```yaml npm run build:second-app ``` ```yaml - name: Create API Key Secret id: create-api-key-secret uses: gcore-github-actions/fastedge/secrets@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} secret_name: "my-backend-api-key" secret_value: "${{ secrets.BACKEND_API_KEY }}" ``` ```yaml - name: Create Api Session Token Secret id: create-api-session-token-secret uses: gcore-github-actions/fastedge/secrets@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} secret_name: "my-api-session-token" secret_slots: "${{ secrets.API_SESSION_TOKEN }}" ``` ```yaml - name: Deploy Second App to FastEdge uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: dist/second-app.wasm app_name: "second-app" env: | environment=production api-url=https://api.example.com/v1/ rsp_headers: | Content-Type=application/json secrets: | api-key=${{ steps.create-api-key-secret.outputs.secret_id }} api-session-token=${{ steps.create-api-session-token-secret.outputs.secret_id }} ``` -------------------------------- ### Get Environment Variable Value Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Retrieves the value of an environment variable set during application deployment. Returns `undefined` if the variable is not found. Ensure the variable is configured in your deployment environment. ```javascript import { getEnv } from "fastedge::env"; const environment = getEnv("environment"); // e.g., "production" const apiUrl = getEnv("api-url"); // e.g., "https://api.example.com/v1/" ``` -------------------------------- ### Build and Deploy AssemblyScript App with GitHub Actions Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Integrates AssemblyScript application building and deployment to FastEdge using GitHub Actions. Requires `pnpm` for package management and AssemblyScript build commands. ```yaml - name: Build AssemblyScript App run: | pnpm install pnpm run asbuild - name: Deploy to FastEdge uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: build/app.wasm app_name: "my-app" ``` -------------------------------- ### Create and Push Semantic Version Tag for Multi-App Deployment Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md Use these commands to create a Git tag for a specific version and push it to the remote repository. This action typically triggers the multi-app deployment workflow. ```bash git tag v1.0.0 git push origin v1.0.0 ``` -------------------------------- ### Multi-Application Deployment Flow with Release Artifacts Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/01-project-overview.md Details a two-phase deployment process for complex projects with multiple applications, triggered by version tags. It includes build caching and separate build/deploy jobs. ```text Tag Push → build_wasm Job: ├─ Fetch previous release artifacts ├─ Git diff current vs previous tag ├─ Rebuild changed apps only (copy unchanged from previous) ├─ Upload artifacts to GitHub release └─ publish_apps Job: ├─ Download latest release artifacts └─ Deploy all apps to FastEdge ``` -------------------------------- ### Creating a Simple Text Response Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Demonstrates the basic instantiation of a Response object with plain text content. ```javascript new Response("Hello World"); ``` -------------------------------- ### Get Specific Secret Version by Slot Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Retrieves a specific version of a secret using its name and slot number. This function supports zero-downtime secret rotation by allowing access to different versions of a secret. Returns `undefined` if the specified secret slot does not exist. ```javascript import { getSecretEffectiveAt } from "fastedge::secret"; const currentToken = getSecretEffectiveAt("api-session-token", 0); const nextToken = getSecretEffectiveAt("api-session-token", 10); ``` -------------------------------- ### Tagging Workflow for Multi-App Semantic Versioning Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md This workflow demonstrates the process of tagging a new release for a multi-application project using Git. It involves committing changes, creating a version tag, and pushing the tag to trigger the build and release process. ```bash # 1. Make code changes git add . git commit -m "Feature: add X" # 2. Create version tag git tag v1.1.0 # 3. Push to trigger workflow git push origin v1.1.0 # 4. Workflow builds and releases # 5. Monitor workflow progress in GitHub Actions ``` -------------------------------- ### FastEdge Deployment for First App Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Deploys a compiled WebAssembly file to FastEdge. Requires API key and specifies the application name. ```yaml - name: Deploy First App to FastEdge uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: dist/first-app.wasm app_name: "first-app" ``` -------------------------------- ### Environment-Specific Deployment with Environment Variables Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md Configures deployment environment and API URLs dynamically using GitHub Actions environment variables based on the branch. ```yaml env: ENVIRONMENT: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} - uses: gcore-github-actions/fastedge/deploy-app@v1 with: env: | environment=${{ env.ENVIRONMENT }} api-url=${{ env.ENVIRONMENT == 'production' && 'https://api.prod.com' || 'https://api.staging.com' }} ``` -------------------------------- ### fastedge-build - Compile JavaScript to WebAssembly Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Compiles JavaScript source files into a WebAssembly binary using the fastedge-build CLI tool. ```APIDOC ## fastedge-build CLI ### Description Compile JavaScript source to WebAssembly binary. ### Command Syntax `npx fastedge-build ` ### Parameters - `input-file` (path): Entry point JavaScript file - `output-file` (path): Output WebAssembly file (.wasm) ### Example ```bash npx fastedge-build ./src/app.js ./dist/app.wasm ``` ### Requirements - Node.js 22.x or later - `@gcoredev/fastedge-sdk-js` installed in node_modules - Entry point must export event listener via `addEventListener("fetch", ...)` ``` -------------------------------- ### Build and Deploy JavaScript App with GitHub Actions Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Integrates JavaScript application building and deployment to FastEdge using GitHub Actions. Ensure the `fastedge-build` tool is available in your PATH. ```yaml - name: Build JavaScript App run: npx fastedge-build ./src/app.js ./dist/app.wasm - name: Deploy to FastEdge uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: dist/app.wasm app_name: "my-app" ``` -------------------------------- ### Build and Deploy Rust App with GitHub Actions Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Integrates Rust application building and deployment to FastEdge using GitHub Actions. Requires `wasm32-wasi` target and `cargo` build tool. ```yaml - name: Build Rust App run: | rustup target add wasm32-wasi cargo build --release --target wasm32-wasi - name: Deploy to FastEdge uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: target/wasm32-wasi/release/app.wasm app_name: "my-app" ``` -------------------------------- ### Add Build Script for New App in package.json Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md This JSON snippet shows how to add a build script to your `package.json` file. The script uses `fastedge-build` to compile your application's entry point into a WASM file. ```json { "scripts": { "build:my-app": "npx fastedge-build ./src/my-app/index.js ./dist/my-app.wasm" } } ``` -------------------------------- ### Deploy FastEdge App with deploy-app Action Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/03-github-actions-deployment.md Use this action to build and deploy a FastEdge application. It supports environment variables, response headers, and secrets. The action automatically checks for configuration differences before updating. ```yaml - uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: dist/first-app.wasm app_name: "first-app" env: | environment=production api-url=https://api.example.com/ rsp_headers: | Content-Type=application/json secrets: | api-key=secret-id-value api-session-token=secret-id-value ``` ```yaml - name: Deploy Second App to FastEdge uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: dist/second-app.wasm app_name: "second-app" env: | environment=production api-url=https://api.example.com/v1/ log-level=debug rsp_headers: | Content-Type=application/json Cache-Control=no-cache secrets: | api-key=${{ steps.create-api-key-secret.outputs.secret_id }} api-session-token=${{ steps.create-api-session-token-secret.outputs.secret_id }} ``` -------------------------------- ### Build Rust Projects for WASM Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Commands to build Rust projects for WebAssembly targets. Use `wasm32-wasi` for WASI-compatible environments and `wasm32-unknown-unknown` for others. ```bash cargo build --release --target wasm32-wasi ``` ```bash cargo build --release --target wasm32-unknown-unknown ``` -------------------------------- ### Upload Release Archive to GitHub Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/03-github-actions-deployment.md Creates a new GitHub Release and attaches the 'release.zip' archive as an asset. It also generates release notes based on the commit history since the last release. ```yaml - name: Upload release archive uses: softprops/action-gh-release@v2 ``` -------------------------------- ### Creating a Response with Custom Status and Header Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Illustrates creating a Response with a specific HTTP status code (201) and a custom header ('x-custom'). ```javascript new Response("content", { status: 201, headers: { "x-custom": "value" } }); ``` -------------------------------- ### AssemblyScript Project asbuild.json Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Configuration for AssemblyScript builds, specifying output files for release and debug targets. ```json { "targets": { "release": { "outFile": "build/app.wasm" }, "debug": { "outFile": "build/app-debug.wasm", "sourceMap": true } } } ``` -------------------------------- ### Creating a JSON Response Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/08-types-and-endpoints.md Shows how to create a Response object with JSON content and set the 'Content-Type' header accordingly. ```javascript new Response(JSON.stringify({key: "value"}), { headers: { "Content-Type": "application/json" } }); ``` -------------------------------- ### Verify API Key and WASM Path for Deployment Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md Check that your GCORE_API_KEY is correctly set in your secrets and that the path to your compiled WASM file matches the build output. This is crucial for successful deployment. ```yaml # Verify API key exists Settings → Secrets → GCORE_API_KEY (should be listed) # Check file path matches build output # After build step, file should exist at: # dist/my-app.wasm # Verify app_name is unique # FastEdge Portal → Applications → Check name not already used ``` -------------------------------- ### Creating a Response Object in JavaScript Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/02-javascript-applications.md Shows how to construct a standard Web API Response object with a body and custom headers. Note that response headers set here can be overridden by deployment configurations. ```javascript new Response(body, { headers: { "header-name": "header-value" } }) ``` -------------------------------- ### Deploy FastEdge App - YAML Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/07-examples-catalog.md Minimal deployment configuration for a FastEdge application using GitHub Actions. Requires an API key and the compiled WASM file. ```yaml uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: dist/first-app.wasm app_name: "first-app" ``` -------------------------------- ### Standard Web APIs - Response Constructor Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/04-fastedge-sdk-reference.md Construct a new Response object to send back to the client. ```APIDOC ## Response Constructor ### Description Construct a new Response object. ### Syntax `new Response(body, { headers: { "Header-Name": "value" } })` ``` -------------------------------- ### Deploy App with API Key Secret Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/03-github-actions-deployment.md This snippet shows how to deploy an application after creating an API key secret. It references the `secret_id` obtained from the `create-api-key-secret` step. ```yaml - name: Deploy App uses: gcore-github-actions/fastedge/deploy-app@v1 with: api_key: ${{ secrets.GCORE_API_KEY }} wasm_file: dist/app.wasm app_name: "myapp" secrets: | api-key=${{ steps.create-api-key-secret.outputs.secret_id }} ``` -------------------------------- ### Handle HTTP Request and Echo URL - JavaScript Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/07-examples-catalog.md Demonstrates basic HTTP request handling by echoing the request URL in a plain text response. Useful as a template for simple HTTP handlers. ```javascript async function eventHandler(event) { const request = event.request; return new Response(`You made a request to ${request.url}`); } addEventListener("fetch", (event) => { event.respondWith(eventHandler(event)); }); ``` -------------------------------- ### Build Javascript Action Configuration Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/05-package-configuration.md Defines the inputs and structure for the 'build-javascript' composite action. It specifies required and optional parameters for building WASM binaries. ```yaml name: "Build Javascript Binary" description: "Uses Node.js to build a Javascript based wasm binary" inputs: # Required inputs wasm_filepath: description: "filepath to built wasm (no trailing slash), e.g. dist" required: true wasm_filename: description: "wasm file name, e.g. first-app.wasm" required: true build_command: description: 'command to build the wasm file, e.g. "npm run build:first-app"' required: true current_release_directory: description: "where to copy the newly built wasm file to" required: true previous_release_directory: description: "where to copy the previously built wasm file from" required: true # Optional inputs working_directory: description: "where to execute commands" required: false default: "." git_diff_directory: description: "directory to check for changes, defaults to working_directory" required: false default: "" runs: using: "composite" steps: # 6 steps for building with change detection ``` -------------------------------- ### Rollback to Previous Release Source: https://github.com/g-core/fastedge-examples/blob/main/_autodocs/06-deployment-guide.md This procedure outlines how to roll back to a previous stable release by creating a new tag pointing to a previous commit. Alternatively, manually download and upload release assets. ```bash # 1. Go to GitHub Releases # 2. Find previous stable version # 3. Manually download release.zip # 4. Upload WASM files to FastEdge Portal # OR # 5. Create new tag pointing to previous commit git tag v1.0.2 git push origin v1.0.2 ```