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:

Terminal
node src/main.js --database-uri=mongodb://db:27017 --database-name=spica \
  --public-url=https://api.example.com/api --master-key=<random-secret> --port=4300

Environment 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

OptionDescription
--database-uriDatabase connection URL.
--database-nameDatabase name. Required for MongoDB, ignored for PostgreSQL.
--public-urlThe 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-keySecret from which every other secret is derived. Required unless you provide all secrets one by one.

Server

OptionDefaultDescription
--port, -p80HTTP port.
--persistent-path/tmpDirectory for persistent data such as function code and default-strategy storage. Mount a volume here.
--cert-file, --key-fileServe HTTPS directly with this certificate and key. Usually TLS is terminated by the ingress instead.
--trust-proxytrueTrust X-Forwarded-* headers: true, false, a number of hops, or a comma-separated list of IPs.
--payload-size-limit15Maximum request body size in MiB.
--common-log-lifespan2592000Seconds after which logs, activity and status records expire (30 days).

Database

OptionDefaultDescription
--database-typemongodbmongodb or postgresql. Fixed for the life of the instance.
--database-replica-set, --replica-setMongoDB replica set name.
--database-pool-size50Connections opened to the database.
--database-read-preferenceprimaryMongoDB read preference: primary, primaryPreferred, secondary, secondaryPreferred, nearest.
--database-change-stream-await-time1000Milliseconds MongoDB waits for new change stream data before returning an empty batch.
Environment variableEffect
MONGODB_USERNAME, MONGODB_PASSWORDInjected into the MongoDB URI.
POSTGRES_USERNAME, POSTGRES_PASSWORDInjected 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.

OptionEnvironment variableProtects
--passport-secret, --secretPASSPORT_SECRETSigning of identity and user JWTs.
--bucket-data-hash-secretBUCKET_DATA_HASH_SECREThash properties and lookups of encrypted ones.
--bucket-data-encryption-secretBUCKET_DATA_ENCRYPTION_SECRETencrypted properties.
--secret-module-encryption-secretSECRET_MODULE_ENCRYPTION_SECRETFunction secrets.
--user-verification-hash-secretUSER_VERIFICATION_HASH_SECRETVerification codes.
--user-provider-encryption-secretUSER_PROVIDER_ENCRYPTION_SECRETUsers' emails, phone numbers and OAuth attributes.
--user-provider-hash-secretUSER_PROVIDER_HASH_SECRETLookups of users' providers.
--refresh-token-hash-secretREFRESH_TOKEN_HASH_SECRETStored refresh tokens.

Buckets

OptionDefaultDescription
--bucket-hookstrueEnable bucket triggers for functions.
--bucket-historytrueEnable document history.
--bucket-graphqlfalseServe GraphQL at /graphql (MongoDB only).
--bucket-cachefalseCache bucket data responses in memory.
--bucket-cache-ttl60Cache lifetime in seconds. Must be positive.
--bucket-data-limitMaximum number of documents across all buckets.
--activity-streamtrueRecord the activity stream.

Passport

OptionDefaultDescription
--passport-default-strategyIDENTITYDefault authentication strategy: IDENTITY or APIKEY.
--passport-default-identity-identifierspicaIdentifier of the default identity.
--passport-default-identity-passwordspicaPassword of the default identity. Change it.
--passport-default-identity-policiesAll full access policiesPolicies of the default identity.
--passport-identity-token-expires-in172800Identity token lifetime in seconds (2 days).
--passport-identity-token-expiration-seconds-limitSame as aboveLongest lifetime a client may request. Can't be lower than the default lifetime.
--passport-identity-refresh-token-expires-in259200Identity refresh token lifetime (3 days).
--passport-identity-password-history-limit0Previous passwords that can't be reused.
--passport-identity-failed-login-attempt-limit0Failed logins before a block. 0 disables it.
--passport-identity-block-duration-after-failed-login-attempts0Block duration in minutes.
--passport-identity-limitMaximum number of identities.
--passport-user-token-expires-in172800User token lifetime.
--passport-user-token-expiration-seconds-limitSame as aboveLongest lifetime a client may request.
--passport-user-refresh-token-expires-in259200User refresh token lifetime.
--passport-user-password-history-limit0Previous passwords that can't be reused.
--passport-user-failed-login-attempt-limit0Failed logins before a block.
--passport-user-block-duration-after-failed-login-attempts0Block duration in minutes.
--passport-user-limitMaximum number of users.
--passport-user-verification-code-expires-in300Verification code lifetime in seconds.
--passport-saml-certificate-ttlUnlimitedLifetime of the self-signed SAML certificate in seconds.

Functions

OptionDefaultDescription
--function-timeout60Upper bound for function timeouts, in seconds.
--function-limitMaximum number of functions.
--function-api-urlhttp://127.0.0.1:<port>URL functions use to reach the API.
--function-builderlegacylegacy or rollup. See Builders.
--function-builder-max-memoryHeap limit of the rollup builder in MB.
--function-worker-concurrency2Parallel workers per function. Must be positive.
--function-worker-event-concurrency100Upper bound for a function's concurrencyPerWorker.
--function-warm-workers-max10Upper bound for a function's warmWorkers. 0 disables warm workers.
--function-worker-cutover-grace-ms30000How long old workers keep serving while new code warms up.
--function-debugfalseStart workers in debugging mode.
--function-loggertrueRecord log levels.
--function-worker-log-outputdatabasedatabase, stdout, or both separated by commas.
--function-invocation-logsfalseLog every invocation to stdout.
--grpc-function-port50051Port of the gRPC trigger server.
--function-grpc-max-message-size-bytes26214400Maximum gRPC message size (25 MiB).
--experimental-function-devkit-database-cachefalseCache @spica-devkit/database connections.

Function source storage

OptionDefaultDescription
--function-asset-storage-strategydefaultdefault, awss3 or gcs.
--function-asset-pathOS temp dirDirectory for function sources with default. Share it between replicas.
--function-asset-awss3-bucket-nameS3 bucket. Required with awss3.
--function-asset-awss3-credentials-pathJSON file with accessKeyId, secretAccessKey, region. Optional; the AWS default credential chain is used otherwise.
--function-asset-gcs-bucket-nameGCS bucket. Required with gcs.
--function-asset-gcs-service-account-pathService account JSON. Required with gcs.

Storage

OptionDefaultDescription
--storage-strategydefaultdefault, awss3 or gcloud.
--default-storage-pathstorageDirectory relative to --persistent-path. Must be relative.
--default-storage-public-url--public-urlBase URL used for object URLs with default.
--awss3-bucket-nameS3 bucket. Required with awss3.
--awss3-credentials-pathCredentials file. Optional; the AWS default credential chain (environment, EKS IRSA, instance profile) is used otherwise.
--gcloud-bucket-nameGCS bucket. Required with gcloud.
--gcloud-service-account-pathService account JSON. Required with gcloud.
--storage-object-size-limit35Maximum object size in MiB.
--storage-total-size-limitTotal storage limit in MB.
--resumable-upload-expires-in172800000Milliseconds before unfinished resumable uploads are removed (2 days).

Mailer and SMS

OptionDefaultDescription
--mailer-host, --mailer-portSMTP server.
--mailer-securefalseUse TLS from the start.
--mailer-user, --mailer-passSMTP credentials.
--mailer-fromDefault sender.
--sms-sender-strategytwilioSMS provider.
--twilio-sms-service-account-sidOr TWILIO_ACCOUNT_SID.
--twilio-sms-service-auth-tokenOr TWILIO_AUTH_TOKEN.
--twilio-sms-service-from-numberOr TWILIO_FROM_NUMBER.

HTTP

OptionDefaultDescription
--cors-allowed-origins*Allowed origins.
--cors-allowed-methods*Allowed methods.
--cors-allowed-headersAuthorization, Content-Type, Accept-LanguageAllowed request headers.
--cors-allow-credentialstrueAccess-Control-Allow-Credentials.
--response-headerHeaders added to every response, as "Name: value" pairs. Pass all of them to a single --response-header.
--cache-control-header, --x-frame-options-headerDeprecated. Use --response-header.
Terminal
--response-header "X-Frame-Options: DENY" "Strict-Transport-Security: max-age=31536000"

Observability and scaling

OptionDefaultDescription
--http-status-trackingtrueCount requests and transferred bytes for /status.
--access-logsfalseLog 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-headerx-request-idHeader logged as proxy_request_id.
--replicationfalseCoordinate 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