Skip to content
tutorial

Deploy Your Application ​

Recommendations ​

  • Replace the default favicon using realfavicongenerator.net
  • Update package.json with a new version number or use npm version patch/minor/major.
  • Harden your configuration for security. See Advanced: Environment Variables and Configurations.
    • Disable CORS if applicable
    • Configure trust_proxies so it only fits your reverse proxy, never set this to true as it allows bypassing rate limits
    • Find a balance between security and user comfort
      • Reduce token_ttl
      • Set token_autorefresh to false
      • Set token_permanent_enabled to false
  • Set api_docs to false if you do not need it

WARNING

Clean up your .env.example file. It should not contain sensitive credentials or deployment-specific configuration like APP_URL. See Advanced: Environment Variables.

Build Your Docker Image ​

bash
docker build -t myapp .

Build the Docker image from your project root. Replace 'myapp' with your preferred tag name.

Orchestrate with Docker Compose ​

Create a .env file in your deployment folder to manage sensitive credentials:

MYSQL_DATABASE=myapp
MYSQL_USER=myapp
MYSQL_PASSWORD=supersecret
MYSQL_ROOT_PASSWORD=verysupersecret

Define your services and networking in a compose.yaml file:

yaml
services:
  app:
    image: myapp
    restart: always
    environment:
      APP_URL: http://myapp.com
      DATABASE_URL: "mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@app-db:3306/${MYSQL_DATABASE}"
    volumes:
      - "./files:/var/files"
      - "./logs:/var/logs"
    ports:
      - "3000:3000"
    depends_on:
      app-db:
        condition: service_healthy

  app-db:
    image: "mysql:9"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
      MYSQL_DATABASE: "${MYSQL_DATABASE}"
      MYSQL_USER: "${MYSQL_USER}"
      MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
    volumes:
      - "./var/mysql:/var/lib/mysql"
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "mysqladmin ping -h localhost -u ${MYSQL_USER} -p${MYSQL_PASSWORD} || exit 1",
        ]
      interval: 5s
      timeout: 5s
      retries: 5
      start_period: 30s
      start_interval: 1s

Start your application and database in detached mode by running:

bash
docker compose up -d