surge
repository·master·Indexed 25 days ago
https://github.com/sintaxi/surgeA 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.
What's inside surge
- 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.
Install Surge CLI via npm
masterInstall the Surge command-line interface globally using npm to enable static web publishing from your terminal.
npm install -g surgePublish a static site with Surge
masterTo publish a static website, run the
surgecommand followed by the directory path you want to deploy and your desired subdomain.Example:
surge <directory> <subdomain>.surge.shsurge . hello.surge.shConfigure Surge via the constructor
masterWhen initializing the
surgefunction, you can provide aconfigurationobject with the following keys:endpoint: The base URL for the Surge API (defaults tohttps://surge.surge.sh).platform: The platform name used to construct the default endpoint (defaults tosurge.sh).name: The name used for CLI/output branding (defaults tosurge).
Troubleshoot SSL/TLS application errors
masterWhen 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 areasonheader, 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.
- 403 Forbidden: The request was aborted. This occurs if you are unauthorized to apply SSL to the specific
Error handling for Surge configuration
masterWhen interacting with the Surge configuration via the SDK, errors may occur during the
sdk.settingscall. The system handles two types of error structures:- Single message error: If the error object contains a
messageproperty, it is displayed asError - <message>. - Multiple message error: If the error object contains a
messagesarray, each message is iterated and displayed asError - <message>.
In both cases, the process will exit with code
1upon encountering a configuration error.- Single message error: If the error object contains a
Access statistics with `surge.stats()`
masterThe
statsnamespace provides usage and traffic metrics for a project. It supports the following verbs:trafficloadaudienceusage
Publish a project with `surge.publish()`
masterThe
publishcommand is used to upload a directory to a Surge domain. It supports various lifecycle hooks for customization.Available hooks for
publish:preAuth,postAuthpreProject,postProjectpreDomain,postDomainpreSize,postSizeprePublish,postPublish
Use Surge hooks to extend command execution
masterMost Surge command functions (e.g.,
surge.publish,surge.login,surge.token) accept an optionalhooksobject. 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.
Access debug information with `surge.debug()`
masterThe
debugnamespace provides diagnostic information for a project. It supports the following verbs:statusfilesauditbustcertsencrypt
Initialize the Surge library
masterThesurgemodule 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 tohttps://surge.surge.shon thesurge.shplatform.Manage DNS settings with `surge.dns()`
masterThe
dnsnamespace provides tools for managing DNS records for a project. It follows the patternsurge <project> dns <verb>orsurge dns <verb>for the current directory.Supported verbs:
list/all: List DNS records.add: Add a record.rem: Remove a record.