Caddy with Firebase backend on Node.js app

1. Output of caddy version:

2.4.6-alpine

2. How I run Caddy:

DigitalOcean Droplet/ Docker compose

a. System environment:

Dockerfile

FROM caddy:2.4.6-alpine
WORKDIR /app
COPY public public
COPY Caddyfile /etc/caddy/
CMD caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

docker-compose.yml

version: '3.7'

services:
  client:
    container_name: caddy-test
    build:
      context: .
      dockerfile: ./Dockerfile
    restart: unless-stopped
    ports:
      - "3007:80"
      # - "443:443"

b. Command:

docker-compose up -d

c. Service/unit/compose file:

Docker compose

d. My complete Caddy config:

locahost {
  root * /app/public
  encode zstd gzip

  handle /__/auth/ {
    reverse_proxy dreem-me-staging.firebaseapp.com
  }
  handle {
    try_files {path} /index.html
    file_server
  }

  header / {
    Cache-Control "no-cache, no-store, must-revalidate"
  }
}

3. The problem I’m having:

We’ve been trying to configure Caddy with Firebase backend on Node.js app. In this configuration file, any URL other than //auth/handler should return index.html (if no other file is available), and //auth/handler should see something like this.

We’ve already tried a few different ways like in this sample:

{$CLIENT_DOMAIN} {
  encode zstd gzip
  header / {
    Cache-Control "no-cache, no-store, must-revalidate"
  }
  reverse_proxy /__/auth {
    to ${FIREBASE_PROJECT_ID}.firebaseapp.com
    header_up Host {upstream_hostport}
  }
  root * /app/public
  try_files {path} /index.{$APP_BUILD}.html
  file_server
}

4. Error messages and/or full log output:

This URL should be proxied to firebase, but now it’s like it’s not there.

5. What I already tried:

Also tried this configuration

{$CLIENT_DOMAIN} {
  encode zstd gzip
  header / {
    Cache-Control "no-cache, no-store, must-revalidate"
  }
  location /__/auth/* {
      reverse_proxy ${FIREBASE_PROJECT_ID}.firebaseapp.com
     header_up Host {upstream_hostport}
   }
  root * /app/public
  try_files {path} /index.{$APP_BUILD}.html
  file_server
}

6. Links to relevant resources:

https://github.com/barinbritva/caddy-test

Hi folks,

Thank you for the great work you’re doing for the community :slight_smile:

Apologies for the late response. We actually forgot to add a header lol :slight_smile:

[SOLVED]

localhost:443 {
  root * /app/public
  encode zstd gzip

  handle /__/auth/* {
    reverse_proxy https://dreem-me-staging.firebaseapp.com {
      header_up Host {upstream_hostport}
    }
  }

  handle {
    try_files {path} /index.html
    file_server
  }

  header / {
    Cache-Control "no-cache, no-store, must-revalidate"
  }
}
3 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.