surge

repository·master·Indexed 25 days ago

https://github.com/sintaxi/surge

A static web publishing platform designed for high-volume, programmatic deployments. Surge allows developers to host static content globally across multiple regions with support for unlimited custom domains. It features an API-first architecture and a CLI for managing deployments, DNS records, project statistics, and account settings. Version 0.40.2.

Tokens
1.8K
Snippets
2
Records
22
Agent score
84%

What's inside surge

  1. Overview of Surge

    master
    Surge is a static web publishing platform with over 14 million deployments across 10 global regions. It features an API-first architecture, meaning every CLI feature is accessible via an API, making it suitable for CI/CD pipelines, automated workflows, and AI-driven programmatic deployments.
  2. Publish a static site with Surge

    master

    To publish a static website, run the surge command followed by the directory path you want to deploy and your desired subdomain.

    Example: surge <directory> <subdomain>.surge.sh

    surge . hello.surge.sh
  3. Configure Surge via the constructor

    master

    When initializing the surge function, you can provide a configuration object with the following keys:

    • endpoint: The base URL for the Surge API (defaults to https://surge.surge.sh).
    • platform: The platform name used to construct the default endpoint (defaults to surge.sh).
    • name: The name used for CLI/output branding (defaults to surge).
  4. Troubleshoot SSL/TLS application errors

    master

    When applying SSL/TLS certificates via Surge, the process may abort due to authorization or credential issues. The middleware handles specific HTTP status codes from the Surge API:

    • 403 Forbidden: The request was aborted. This occurs if you are unauthorized to apply SSL to the specific req.domain. If the response includes a reason header, that reason will be displayed.
    • 401 Unauthorized: The local token has expired. The middleware will attempt to clear the local credentials for the current endpoint. You should try logging in again to refresh your token.

    If an error occurs during the handshake process, the error details are logged to the console.

  5. Error handling for Surge configuration

    master

    When interacting with the Surge configuration via the SDK, errors may occur during the sdk.settings call. The system handles two types of error structures:

    1. Single message error: If the error object contains a message property, it is displayed as Error - <message>.
    2. Multiple message error: If the error object contains a messages array, each message is iterated and displayed as Error - <message>.

    In both cases, the process will exit with code 1 upon encountering a configuration error.

  6. Publish a project with `surge.publish()`

    master

    The publish command is used to upload a directory to a Surge domain. It supports various lifecycle hooks for customization.

    Available hooks for publish:

    • preAuth, postAuth
    • preProject, postProject
    • preDomain, postDomain
    • preSize, postSize
    • prePublish, postPublish
  7. Use Surge hooks to extend command execution

    master

    Most Surge command functions (e.g., surge.publish, surge.login, surge.token) accept an optional hooks object. This allows you to inject custom logic at various stages of the command lifecycle.

    Common hook names include:

    • preAuth / postAuth: Executed before and after authentication checks.
    • preProject / postProject: Executed around project discovery/resolution.
    • preDomain / postDomain: Executed around domain resolution.
    • prePublish / postPublish: Executed around the publishing process.
    • preSize / postSize: Executed around file size calculations.
    • preEncrypt / postEncrypt: Executed around encryption tasks.
  8. Initialize the Surge library

    master
    The surge module can be initialized with a configuration object to customize the API's behavior, such as the endpoint or platform. If no configuration is provided, it defaults to https://surge.surge.sh on the surge.sh platform.
  9. Manage DNS settings with `surge.dns()`

    master

    The dns namespace provides tools for managing DNS records for a project. It follows the pattern surge <project> dns <verb> or surge dns <verb> for the current directory.

    Supported verbs:

    • list / all: List DNS records.
    • add: Add a record.
    • rem: Remove a record.