API configuration reference
Every startup option of the Spica API, grouped by area, with defaults, environment variables and validation rules.
The API is configured with command-line options:
node src/main.js --database-uri=mongodb://db:27017 --database-name=spica \
--public-url=https://api.example.com/api --master-key=<random-secret> --port=4300Environment variables. Every option can also be given as an environment variable: upper case, with _ instead of -. For example --database-uri becomes DATABASE_URI and --bucket-cache-ttl becomes BUCKET_CACHE_TTL. Command-line options take precedence.
Booleans accept --flag, --flag=true and --flag=false. Arrays accept repeated values, for example --cors-allowed-origins https://a.com https://b.com.
Run node src/main.js --help in the API container to print every option of your version.
Required
| Option | Description |
|---|---|
--database-uri | Database connection URL. |
--database-name | Database name. Required for MongoDB, ignored for PostgreSQL. |
--public-url | The URL clients use to reach the API, for example https://example.com/api. Used for storage URLs, OAuth redirects, magic links and token issuers. Alias: --public-host. |
--master-key | Secret from which every other secret is derived. Required unless you provide all secrets one by one. |
Server
| Option | Default | Description |
|---|---|---|
--port, -p | 80 | HTTP port. |
--persistent-path | /tmp | Directory for persistent data such as function code and default-strategy storage. Mount a volume here. |
--cert-file, --key-file | Serve HTTPS directly with this certificate and key. Usually TLS is terminated by the ingress instead. | |
--trust-proxy | true | Trust X-Forwarded-* headers: true, false, a number of hops, or a comma-separated list of IPs. |
--payload-size-limit | 15 | Maximum request body size in MiB. |
--common-log-lifespan | 2592000 | Seconds after which logs, activity and status records expire (30 days). |
Database
| Option | Default | Description |
|---|---|---|
--database-type | mongodb | mongodb or postgresql. Fixed for the life of the instance. |
--database-replica-set, --replica-set | MongoDB replica set name. | |
--database-pool-size | 50 | Connections opened to the database. |
--database-read-preference | primary | MongoDB read preference: primary, primaryPreferred, secondary, secondaryPreferred, nearest. |
--database-change-stream-await-time | 1000 | Milliseconds MongoDB waits for new change stream data before returning an empty batch. |
| Environment variable | Effect |
|---|---|
MONGODB_USERNAME, MONGODB_PASSWORD | Injected into the MongoDB URI. |
POSTGRES_USERNAME, POSTGRES_PASSWORD | Injected into the PostgreSQL URI. |
Secrets
When --master-key (or MASTER_KEY) is set, every secret below is derived from it unless you set it explicitly. Without a master key, all of them are required.
| Option | Environment variable | Protects |
|---|---|---|
--passport-secret, --secret | PASSPORT_SECRET | Signing of identity and user JWTs. |
--bucket-data-hash-secret | BUCKET_DATA_HASH_SECRET | hash properties and lookups of encrypted ones. |
--bucket-data-encryption-secret | BUCKET_DATA_ENCRYPTION_SECRET | encrypted properties. |
--secret-module-encryption-secret | SECRET_MODULE_ENCRYPTION_SECRET | Function secrets. |
--user-verification-hash-secret | USER_VERIFICATION_HASH_SECRET | Verification codes. |
--user-provider-encryption-secret | USER_PROVIDER_ENCRYPTION_SECRET | Users' emails, phone numbers and OAuth attributes. |
--user-provider-hash-secret | USER_PROVIDER_HASH_SECRET | Lookups of users' providers. |
--refresh-token-hash-secret | REFRESH_TOKEN_HASH_SECRET | Stored refresh tokens. |
Buckets
| Option | Default | Description |
|---|---|---|
--bucket-hooks | true | Enable bucket triggers for functions. |
--bucket-history | true | Enable document history. |
--bucket-graphql | false | Serve GraphQL at /graphql (MongoDB only). |
--bucket-cache | false | Cache bucket data responses in memory. |
--bucket-cache-ttl | 60 | Cache lifetime in seconds. Must be positive. |
--bucket-data-limit | Maximum number of documents across all buckets. | |
--activity-stream | true | Record the activity stream. |
Passport
| Option | Default | Description |
|---|---|---|
--passport-default-strategy | IDENTITY | Default authentication strategy: IDENTITY or APIKEY. |
--passport-default-identity-identifier | spica | Identifier of the default identity. |
--passport-default-identity-password | spica | Password of the default identity. Change it. |
--passport-default-identity-policies | All full access policies | Policies of the default identity. |
--passport-identity-token-expires-in | 172800 | Identity token lifetime in seconds (2 days). |
--passport-identity-token-expiration-seconds-limit | Same as above | Longest lifetime a client may request. Can't be lower than the default lifetime. |
--passport-identity-refresh-token-expires-in | 259200 | Identity refresh token lifetime (3 days). |
--passport-identity-password-history-limit | 0 | Previous passwords that can't be reused. |
--passport-identity-failed-login-attempt-limit | 0 | Failed logins before a block. 0 disables it. |
--passport-identity-block-duration-after-failed-login-attempts | 0 | Block duration in minutes. |
--passport-identity-limit | Maximum number of identities. | |
--passport-user-token-expires-in | 172800 | User token lifetime. |
--passport-user-token-expiration-seconds-limit | Same as above | Longest lifetime a client may request. |
--passport-user-refresh-token-expires-in | 259200 | User refresh token lifetime. |
--passport-user-password-history-limit | 0 | Previous passwords that can't be reused. |
--passport-user-failed-login-attempt-limit | 0 | Failed logins before a block. |
--passport-user-block-duration-after-failed-login-attempts | 0 | Block duration in minutes. |
--passport-user-limit | Maximum number of users. | |
--passport-user-verification-code-expires-in | 300 | Verification code lifetime in seconds. |
--passport-saml-certificate-ttl | Unlimited | Lifetime of the self-signed SAML certificate in seconds. |
Functions
| Option | Default | Description |
|---|---|---|
--function-timeout | 60 | Upper bound for function timeouts, in seconds. |
--function-limit | Maximum number of functions. | |
--function-api-url | http://127.0.0.1:<port> | URL functions use to reach the API. |
--function-builder | legacy | legacy or rollup. See Builders. |
--function-builder-max-memory | Heap limit of the rollup builder in MB. | |
--function-worker-concurrency | 2 | Parallel workers per function. Must be positive. |
--function-worker-event-concurrency | 100 | Upper bound for a function's concurrencyPerWorker. |
--function-warm-workers-max | 10 | Upper bound for a function's warmWorkers. 0 disables warm workers. |
--function-worker-cutover-grace-ms | 30000 | How long old workers keep serving while new code warms up. |
--function-debug | false | Start workers in debugging mode. |
--function-logger | true | Record log levels. |
--function-worker-log-output | database | database, stdout, or both separated by commas. |
--function-invocation-logs | false | Log every invocation to stdout. |
--grpc-function-port | 50051 | Port of the gRPC trigger server. |
--function-grpc-max-message-size-bytes | 26214400 | Maximum gRPC message size (25 MiB). |
--experimental-function-devkit-database-cache | false | Cache @spica-devkit/database connections. |
Function source storage
| Option | Default | Description |
|---|---|---|
--function-asset-storage-strategy | default | default, awss3 or gcs. |
--function-asset-path | OS temp dir | Directory for function sources with default. Share it between replicas. |
--function-asset-awss3-bucket-name | S3 bucket. Required with awss3. | |
--function-asset-awss3-credentials-path | JSON file with accessKeyId, secretAccessKey, region. Optional; the AWS default credential chain is used otherwise. | |
--function-asset-gcs-bucket-name | GCS bucket. Required with gcs. | |
--function-asset-gcs-service-account-path | Service account JSON. Required with gcs. |
Storage
| Option | Default | Description |
|---|---|---|
--storage-strategy | default | default, awss3 or gcloud. |
--default-storage-path | storage | Directory relative to --persistent-path. Must be relative. |
--default-storage-public-url | --public-url | Base URL used for object URLs with default. |
--awss3-bucket-name | S3 bucket. Required with awss3. | |
--awss3-credentials-path | Credentials file. Optional; the AWS default credential chain (environment, EKS IRSA, instance profile) is used otherwise. | |
--gcloud-bucket-name | GCS bucket. Required with gcloud. | |
--gcloud-service-account-path | Service account JSON. Required with gcloud. | |
--storage-object-size-limit | 35 | Maximum object size in MiB. |
--storage-total-size-limit | Total storage limit in MB. | |
--resumable-upload-expires-in | 172800000 | Milliseconds before unfinished resumable uploads are removed (2 days). |
Mailer and SMS
| Option | Default | Description |
|---|---|---|
--mailer-host, --mailer-port | SMTP server. | |
--mailer-secure | false | Use TLS from the start. |
--mailer-user, --mailer-pass | SMTP credentials. | |
--mailer-from | Default sender. | |
--sms-sender-strategy | twilio | SMS provider. |
--twilio-sms-service-account-sid | Or TWILIO_ACCOUNT_SID. | |
--twilio-sms-service-auth-token | Or TWILIO_AUTH_TOKEN. | |
--twilio-sms-service-from-number | Or TWILIO_FROM_NUMBER. |
HTTP
| Option | Default | Description |
|---|---|---|
--cors-allowed-origins | * | Allowed origins. |
--cors-allowed-methods | * | Allowed methods. |
--cors-allowed-headers | Authorization, Content-Type, Accept-Language | Allowed request headers. |
--cors-allow-credentials | true | Access-Control-Allow-Credentials. |
--response-header | Headers added to every response, as "Name: value" pairs. Pass all of them to a single --response-header. | |
--cache-control-header, --x-frame-options-header | Deprecated. Use --response-header. |
--response-header "X-Frame-Options: DENY" "Strict-Transport-Security: max-age=31536000"Observability and scaling
| Option | Default | Description |
|---|---|---|
--http-status-tracking | true | Count requests and transferred bytes for /status. |
--access-logs | false | Log HTTP requests to stdout. |
--access-logs-url-filter | .* | Regex of URLs to log. |
--access-logs-statuscode-filter | .* | Regex of status codes to log. |
--access-logs-proxy-request-id-header | x-request-id | Header logged as proxy_request_id. |
--replication | false | Coordinate several API replicas. See Replication. |
Validation
The API refuses to start when options contradict each other, for example:
--gcloud-service-account-path and --gcloud-bucket-name options must be present when --storage-strategy is set to 'gcloud'.--default-storage-path must be relative.--passport-user-token-expiration-seconds-limit(...) can not be less than --passport-user-token-expires-in(...)passport-secret is required when the master-key is not provided