Git Product home page Git Product logo

reverse-proxy's Introduction

Caddy Frontend & Backend Reverse Proxy

Combine your separate frontend and backend services into one domain!

Access the frontend from /* and access the backend from /api/* on the same domain

Frontend - Vue 3: https://mysite.up.railway.app/

Backend - Go Mux: https://mysite.up.railway.app/api/

The proxy configurations are done in the Caddyfile everything is commented for your ease of use!

When deploying your Reverse Proxy service it will require you to set two service variables: FRONTEND_HOST and BACKEND_HOST

Note: You will first need to have set a fixed PORT variable in both the frontend and backend services before deploying this template

These are the two template variables that you will be required to fill out during the first deployment of this service, replace the respective <frontend service name> and <backend service name> with the service names as they appear in the Railway project view

FRONTEND_HOST = ${{<frontend service name>.RAILWAY_PRIVATE_DOMAIN}}:${{<frontend service name>.PORT}}
BACKEND_HOST = ${{<backend service name>.RAILWAY_PRIVATE_DOMAIN}}:${{<backend service name>.PORT}}

Relevant Caddy documentation:

Some prerequisites to help with common issues that could arise:

  • Both the frontend and backend need to listen on fixed ports, in my Caddyfile I have used port 3000 in the proxy address, and configured my frontend and backend to both listen on port 3000

  • Since Railway's internal network is IPv6 only the frontend and backend apps will need to listen on :: (all interfaces - both IPv4 and IPv6)

    Start commands for some popular frameworks:

    • Gunicorn: gunicorn main:app -b [::]:$PORT

    • Uvicorn: uvicorn main:app --host :: --port $PORT

      • Uvicorn does not support dual stack binding (IPv6 and IPv4) from the CLI, so while that start command will work to enable access from within the private network, this prevents you from accessing the app from the public domain if needed, I recommend using Hypercorn instead
    • Hypercorn: hypercorn main:app --bind [::]:$PORT

    • Next: next start -H :: --port $PORT

    • Express/Nest: app.listen(process.env.PORT, "::");

reverse-proxy's People

Contributors

railway-bot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.