AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Configuring Environment Secrets, Persistent PostgreSQL, and Custom Domains in Replit Deployments

365Finds Editorial
Indexed 11,430 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Deploying a web application from a development workspace to a production environment requires three essential pillars: secure credential isolation, persistent and resilient relational data storage, and branded, encrypted domain routing. In Replit, transforming an interactive prototype into a production-ready application centers around Replit Deployments (accessible via the Publishing tool). Rather than treating hosting as an afterthought, Replit integrates compute provisioning, serverless PostgreSQL, secret management, and automated TLS certificate handling into a single deployment pipeline.

This guide walks through configuring environment secrets, setting up persistent PostgreSQL databases, and wiring custom domains with permanent SSL/TLS verification in Replit Deployments.


1. Choosing the Right Deployment Architecture

Before configuring storage or credentials, you must select the deployment model suited to your workload under Publishing → Adjust settings → Deployment type:

For most web services requiring relational persistence and secret management, Autoscale or Reserved VM is the appropriate foundation.


2. Managing Production Environment Secrets

A common vulnerability during deployment is the leakage or mismatch of API keys, authentication credentials, and service tokens. Replit separates your workspace into two distinct secret scopes: Development Secrets and Deployment Secrets.

Understanding Secret Scopes

Step-by-Step Configuration

  1. Audit Sensitive Values: Identify third-party API credentials (Stripe, OpenAI, Clerk, OAuth client secrets) and application keys. Differentiate between sensitive Secrets (encrypted at rest with AES-256 and transmitted via TLS) and non-sensitive Configurations (such as LOG_LEVEL=info or public CDN prefixes).
  2. Set Deployment Secrets: Open the Publishing tool, navigate to Adjust settings, and inspect the Deployment secrets section. Add or verify each key-value pair needed for production.
  3. Trigger a Redeployment: When you update secrets in a live application, open the Publishing tool and click Publish (or re-publish). New environment variables take effect only when a new container build is deployed.

Accessing Secrets in Application Code

Secrets are injected as standard environment variables. Never hardcode fallback credentials in version control.

In Node.js / TypeScript:

const apiKey = process.env.STRIPE_SECRET_KEY;
if (!apiKey) {
  throw new Error("STRIPE_SECRET_KEY is required in production environment");
}

In Python:

import os

api_key = os.environ.get("STRIPE_SECRET_KEY")
if not api_key:
    raise RuntimeError("STRIPE_SECRET_KEY is missing from environment")

Note on System Variables: Environment variables generated exclusively for development previews (such as REPLIT_DEV_DOMAIN) are omitted in production containers. Always reference production hostnames using your custom domain configuration or custom environment variables.


3. Configuring Persistent PostgreSQL for Production

Every Replit App comes with access to managed PostgreSQL, but development and production utilize fundamentally different underlying architectures.

Architecture: Development (Helium) vs. Production (Neon)

Connection Management and DATABASE_URL

Replit automatically provisions and sets the DATABASE_URL environment variable in both your development workspace and production deployment:

Solving the Production SSL Requirement

Because the local development database (Helium) does not support SSL handshakes, while production Neon PostgreSQL mandates TLS/SSL, your database client must configure SSL conditionally. Hardcoding SSL settings causes connection failures in either development or production.

Example: PostgreSQL Client Pool Configuration (Node.js pg)

import { Pool } from "pg";

const isProduction = process.env.NODE_ENV === "production";

export const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  ssl: isProduction ? { rejectUnauthorized: false } : false,
});

Example: Prisma or Drizzle ORM

When configuring schema connections or client wrappers:

import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  ssl: process.env.NODE_ENV === "production" ? { rejectUnauthorized: false } : false,
});

export const db = drizzle(pool);

Serverless Connection Pooling

Autoscale deployments dynamically spin up multiple application replicas during sudden traffic surges. Unpooled direct connections to PostgreSQL can rapidly exhaust connection limits (max_connections).

To enable connection pooling:

  1. Examine the production connection string in the Database tool settings.
  2. Production databases hosted on Neon provide a pooled connection host by attaching -pooler to the host segment (for example, ep-xyz-pooler.region.neon.tech).
  3. Use the pooled connection string for ephemeral query transactions in high-concurrency Autoscale deployments, while reserving direct connections for migration tasks that require session-level locking.

Safe Migrations and Deployment Previews

When applying schema migrations (such as adding non-nullable columns, altering types, or renaming tables):


4. Connecting and Securing Custom Domains

By default, published deployments receive a free .replit.app subdomain. For commercial reliability and branding, configuring a custom domain (both root apex and subdomains) is critical.

Replit automates Let's Encrypt / Google Trust TLS/SSL certificate issuance and renewal via automated DNS validation. However, misconfigured DNS records or deleted validation tokens will cause silent renewal failures.

Step-by-Step Custom Domain Setup

1. Add Domain in the Publishing Tool

  1. In the Project Editor, open Publishing → select the Domains tab.
  2. Enter your custom domain (e.g., example.com).
  3. Replit displays the target IP address for the A record and a custom verification string for a TXT record.

2. Configure DNS Records at Your Registrar

Log into your DNS provider (such as Cloudflare, Namecheap, GoDaddy, or AWS Route 53) and configure the following records:

Record TypeHostname / NameTarget / ValuePurpose
A@ (or root domain)[Replit IP address]Routes web traffic to your deployment
TXT@ (or root domain)replit-verify=xxxxxxxx...Authorizes domain ownership & TLS issuance

3. Resolve Common DNS Pitfalls

Configuring Subdomains and the www Redirect

Replit treats apex domains and subdomains as independent routing endpoints:


5. Production Readiness Verification Checklist

Before directing live user traffic to your Replit deployment, perform this end-to-end verification:

  1. Environment Secrets Audit:
    • Verify all third-party API keys exist under Publishing → Adjust settings → Deployment secrets.
    • Confirm no sensitive API keys are checked into repository files or .replit configs.
    • Trigger a clean deployment build to apply secret updates.
  2. Database Resilience & Connectivity:
    • Ensure database connection code handles TLS/SSL conditionally (rejectUnauthorized: false when NODE_ENV === "production").
    • Confirm the application relies on the system-injected DATABASE_URL rather than hardcoded connection parameters.
    • Verify that migrations run cleanly during deployment startup without hanging.
  3. Domain & Security Health:
    • Verify that both apex and www domains display the Verified status badge in the Replit Domains tab.
    • Confirm HTTPS loads with a valid certificate across desktop and mobile browsers.
    • Ensure the replit-verify TXT record remains saved in your registrar DNS management table.
  4. Monitoring & Health Checks:
    • Enable the built-in Monitoring tools in the Publishing pane to receive instant email notifications upon downtime or elevated HTTP error rates.
    • Choose a Deployment geography close to your primary audience (note: once deployed, geography is fixed to that instance).

By isolating secrets between development and deployment, wrapping database drivers in environment-aware SSL wrappers, and maintaining permanent DNS validation records, you establish a resilient, scalable, and secure production foundation on Replit.


References