Angular + Caddyfile + Api reverse proxy

Hi, i'm having issues with reverse proxy in my frontend caddy server, when i'm making calls to my backend with this reverse_proxy, i get 405 http error, i tried several things and changes, adjust my backend app to listen in IPV6, the order in the caddyfile, add the port at the reverseproxy call, and several other things, this is my caddyfile now:

# global options
{
    admin off # theres no need for the admin api in railway's environment
    persist_config off # storage isn't persistent anyway
    auto_https off # railway handles https for us, this would cause issues if left enabled
    # runtime logs
    log {
        format json # set runtime log format to json mode
    }
    # server options
    servers {
        trusted_proxies static private_ranges # trust railway's proxy
    }
}

# site block, listens on the $PORT environment variable, automatically assigned by railway
:{$PORT} {
  @origin header Origin *
  header @origin Access-Control-Allow-Origin "*"
  header @origin Access-Control-Allow-Methods "OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE"
  header @origin Allow "OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE"

    # access logs
    log {
        format json # set access log format to json mode
    }

  reverse_proxy /api/* wwt-auth.railway.internal:8080


    # health check for railway
    rewrite /health /*

    # serve from the set folder
    root * {$ANGULAR_OUTPUT_PATH}

    # enable gzipping responses
    encode gzip

    # serve files
    file_server

    # if path doesn't exist, redirect it to 'index.html' for client side routing
    try_files {path} /index.html
}

When calling in the frontend, in network tab i get this error

URL De La Solicitud: https://frontend-main-production.up.railway.app/api/auth/sign-in
M茅todo De Solicitud: POST
C贸digo De Estado: 405 Method Not Allowed
Direcci贸n Remota: 34.86.119.124:443
Directiva De Sitio De Referencia: strict-origin-when-cross-origin
Access-Control-Allow-Methods: OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE
Access-Control-Allow-Origin: *
Allow: OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE
Allow: GET, HEAD
Content-Length: 0
Date: Mon, 06 May 2024 00:09:38 GMT
Server: railway

in my backend my actual port it is 8080

await app.listen(
  configService.get('port'), // PORT: 8080
  '::'
);

do anyone have some idea of what it is going on 馃槮

0 Replies

a year ago

please do not cross post


039db255-1661-4af2-9432-105d00623d68


I'm just trying to find a solution, i have been googling till 2 days ago


a year ago

this is community support, please be patient, creating duplicate posts won't help anything


Angular + Caddyfile + Api reverse proxy - Railway Help Station