.well-known directory?
amunrarara
PROOP

2 years ago

I'm attempting to place a file in my .well-known directory, but I'm unsure how to do so while using Railway.

Solved

6 Replies

2 years ago

What kind of app?


amunrarara
PROOP

2 years ago

Dockerized NextJS app. I tried including public/.well-known, however the files within are not accessible via https://my-domain.com/.well-known/file.json


2 years ago

Are you able to provide a minimal reproducible example?


2 years ago

Does it work if you access it locally? Are you including it in your build?


Status changed to Awaiting User Response Railway over 1 year ago


amunrarara
PROOP

2 years ago

Sorry for the delay there. I've finally managed to get this working.

Here's my current Caddyfile:

# Global options
{
    # Disable the admin API as it's not needed in most environments
    admin off

    # Disable automatic HTTPS as it's often handled by external services
    auto_https off

    # Configure logging in JSON format for better parsing
    log {
        format json
    }

    # Trust private ranges as proxies, useful in container environments
    servers {
        trusted_proxies static private_ranges
    }
}

# Main server block, using the PORT environment variable
:{$PORT} {
    # Set the root directory using an environment variable for flexibility
    root * {$SERVE_DIR}

    # Handle requests to the .well-known directory
    @wellknown {
        path /.well-known/*
    }
    handle @wellknown {
        # Strip the /.well-known prefix from the URI
        uri strip_prefix /.well-known
        # Set the root specifically for .well-known requests
        root * {$SERVE_DIR}/.well-known
        # Serve files from this directory
        file_server
    }

    # Ensure correct MIME type for nostr.json
    header /nostr.json Content-Type application/json

    # Enable Gzip and Zstandard compression for better performance
    encode gzip zstd

    # Define static file types and set caching headers
    @static {
        file
        path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.woff2 *.json
    }
    header @static Cache-Control "public, max-age=3600"

    # Support for Single Page Applications (SPA) routing
    try_files {path} /index.html

    # Custom error handling
    handle_errors {
        # Rewrite to the appropriate error page
        rewrite * /{http.error.status_code}.html
        file_server
    }

    # Enable static file serving for all other requests
    file_server
}

Here's my Dockerfile:

FROM caddy:alpine

RUN apk update && apk add --no-cache nodejs yarn

WORKDIR /app

COPY package*.json ./
RUN yarn install

COPY . .

ARG BUILD_COMMAND=build
RUN yarn ${BUILD_COMMAND}

ENV SERVE_DIR=/app/dist

COPY ./Caddyfile /etc/caddy/Caddyfile

CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]

Status changed to Awaiting Railway Response Railway over 1 year ago


2 years ago

Glad you were able to solve this!


Status changed to Awaiting User Response Railway over 1 year ago


Status changed to Solved brody over 1 year ago


Loading...