Static web publishing CLI tool for deploying web applications to a CDN with a single command
—
Project and platform configuration management for customizing Surge deployments, managing project settings, and configuring platform behavior.
View and modify project and platform configuration settings.
/**
* View and change project configuration settings
* @param hooks - Optional lifecycle hooks
* @returns Command function
*/
function config(hooks?: HookConfig): CommandFunction;CLI Usage:
# View project configuration
surge config example.surge.sh
# Interactive configuration menu
surge config
# Set specific configuration value
surge config example.surge.sh --set ssl.enabled true
# View global platform settings
surge config --globalConfiguration Options:
Library Usage:
surge.config({})(process.argv.slice(2));Project Metadata:
# Set project name
surge config example.surge.sh --name "My Website"
# Set project description
surge config example.surge.sh --description "Company marketing site"
# Set project tags
surge config example.surge.sh --tags "production,marketing,website"Deployment Settings:
# Set default deployment directory
surge config example.surge.sh --build-dir ./dist
# Set deployment branch
surge config example.surge.sh --branch main
# Enable/disable automatic deployments
surge config example.surge.sh --auto-deploy trueCustom Domains:
# Set custom domain
surge config example.surge.sh --domain example.com
# Configure domain aliases
surge config example.surge.sh --aliases www.example.com,app.example.com
# Set apex domain redirect
surge config example.surge.sh --apex-redirect www.example.comSSL Configuration:
# Enable SSL
surge config example.surge.sh --ssl enabled
# Set SSL provider
surge config example.surge.sh --ssl-provider letsencrypt
# Configure SSL enforcement
surge config example.surge.sh --ssl-enforce true
# Set custom SSL certificate
surge config example.surge.sh --ssl-cert ./cert.pem --ssl-key ./key.pemBuild Settings:
# Set build command
surge config example.surge.sh --build-command "npm run build"
# Set build directory
surge config example.surge.sh --build-output "./dist"
# Configure environment variables
surge config example.surge.sh --env NODE_ENV=production --env API_URL=https://api.example.com
# Set build timeout
surge config example.surge.sh --build-timeout 300File Processing:
# Configure ignore patterns
surge config example.surge.sh --ignore "*.log,node_modules/*,src/*"
# Set compression options
surge config example.surge.sh --compression gzip,brotli
# Configure cache headers
surge config example.surge.sh --cache-control "public, max-age=31536000"CLI Defaults:
# Set default project directory
surge config --global --default-project ./build
# Set default domain pattern
surge config --global --domain-pattern "%s.surge.sh"
# Configure authentication preferences
surge config --global --auth-method tokenDisplay Settings:
# Set output format
surge config --global --output-format table
# Configure color scheme
surge config --global --colors auto
# Set verbosity level
surge config --global --verbose 2Organization Settings:
# Set organization name
surge config --org --name "Acme Corp"
# Configure team defaults
surge config --org --default-ssl enabled
# Set billing preferences
surge config --org --billing-email finance@acme.comAccess Control:
# Configure IP whitelist
surge config --org --ip-whitelist 192.168.1.0/24,10.0.0.0/8
# Set 2FA requirements
surge config --org --require-2fa true
# Configure session timeout
surge config --org --session-timeout 8h.surge Directory:
project-root/
├── .surge/
│ ├── config.json # Project configuration
│ ├── secrets.json # Environment variables (gitignored)
│ ├── hooks/ # Custom deployment hooks
│ └── templates/ # Deployment templates
├── CNAME # Domain configuration
├── .surgeignore # File ignore patterns
└── surge.json # Alternative config fileProject Config (config.json):
{
"domain": "example.surge.sh",
"buildCommand": "npm run build",
"buildDir": "./dist",
"ssl": {
"enabled": true,
"provider": "letsencrypt",
"enforce": true
},
"redirects": {
"/old-page": "/new-page",
"/api/*": "https://api.example.com/$1"
},
"headers": {
"/*": {
"Cache-Control": "public, max-age=31536000",
"X-Frame-Options": "DENY"
}
}
}User Config (~/.surge/config.json):
{
"email": "user@example.com",
"defaultProject": "./build",
"domainPattern": "%s.surge.sh",
"outputFormat": "table",
"colors": true,
"verbose": 1
}Credentials (~/.netrc):
machine surge.surge.sh
login user@example.com
password api-token-hereAuthentication:
SURGE_TOKEN: API token for authenticationSURGE_LOGIN: Email address for loginSURGE_PASSWORD: Password for login (not recommended)Configuration:
SURGE_DOMAIN: Default domain for deploymentsSURGE_PROJECT: Default project directorySURGE_ENDPOINT: Custom API endpointSURGE_PLATFORM: Platform identifierBuild Environment:
NODE_ENV: Node.js environmentBUILD_ENV: Build environment identifierAPI_URL: API endpoint URLCDN_URL: CDN base URLSetting Variables:
# Set environment variable
surge config example.surge.sh --env API_KEY=secret123
# Set multiple variables
surge config example.surge.sh --env API_KEY=secret123 --env DEBUG=true
# Load from file
surge config example.surge.sh --env-file .env.productionUsing Variables:
// In your application
const apiKey = process.env.API_KEY;
const apiUrl = process.env.API_URL || 'https://api.example.com';Security Headers:
# Set security headers
surge config example.surge.sh --header "X-Frame-Options: DENY"
surge config example.surge.sh --header "X-Content-Type-Options: nosniff"
surge config example.surge.sh --header "X-XSS-Protection: 1; mode=block"Cache Control:
# Set cache headers for different file types
surge config example.surge.sh --header "*.css: Cache-Control: public, max-age=31536000"
surge config example.surge.sh --header "*.js: Cache-Control: public, max-age=31536000"
surge config example.surge.sh --header "*.html: Cache-Control: no-cache"Redirect Configuration:
# Simple redirect
surge config example.surge.sh --redirect "/old-url /new-url"
# Pattern redirects
surge config example.surge.sh --redirect "/blog/* /articles/$1"
# External redirects
surge config example.surge.sh --redirect "/external https://external-site.com"SPA Configuration:
# Configure single-page application
surge config example.surge.sh --spa true
# Custom 404 page
surge config example.surge.sh --404 custom-404.html
# Fallback for client-side routing
surge config example.surge.sh --fallback 200.htmlError Page Configuration:
# Set custom 404 page
surge config example.surge.sh --error-page 404 ./404.html
# Set custom 500 page
surge config example.surge.sh --error-page 500 ./500.html
# Set maintenance page
surge config example.surge.sh --maintenance-page ./maintenance.htmlExport Configuration:
# Export project configuration
surge config example.surge.sh --export > config-backup.json
# Export global configuration
surge config --global --export > global-config.json
# Export all configurations
surge config --export-all > all-configs.jsonImport Configuration:
# Import project configuration
surge config example.surge.sh --import config-backup.json
# Import global configuration
surge config --global --import global-config.jsonVersion Control:
# Track configuration changes
surge config example.surge.sh --version-control enable
# View configuration history
surge config example.surge.sh --history
# Revert to previous configuration
surge config example.surge.sh --revert v1.2.3Create Templates:
# Create configuration template
surge config --template spa-template --spa true --ssl enabled
# Apply template to project
surge config example.surge.sh --apply-template spa-template
# List available templates
surge config --list-templatesInvalid Configuration:
# Validate configuration
surge config example.surge.sh --validate
# Fix configuration errors
surge config example.surge.sh --fix-errors
# Reset to defaults
surge config example.surge.sh --resetMissing Configuration:
# Check required settings
surge config example.surge.sh --check-required
# Set missing defaults
surge config example.surge.sh --set-defaults
# Interactive configuration setup
surge config example.surge.sh --setupVariable Not Available:
Configuration Conflicts:
# Check configuration hierarchy
surge config example.surge.sh --show-hierarchy
# Resolve conflicts
surge config example.surge.sh --resolve-conflicts
# Debug configuration loading
surge config example.surge.sh --debugBuild Failures:
SSL Configuration Problems:
Install with Tessl CLI
npx tessl i tessl/npm-surge