ECONNREFUSED in flask app + next.js
piotrpomorski
PROOP

a year ago

Hi, I have deployed my app which uses flask (waitress) for backend and next.js for frontend, while it works perfectly locally, I keep getting ECONNREFUSED even when accessing /api/ to check for "Flask server is running":

@app.route("/", methods=["GET"])
def index():
    logger.debug("Accessing root route")
    return jsonify({"message": "Flask server is running"})

where instead I get "Internal Server Error" (after checking the logs, it's just ECONNREFUSED). Do flask apps need to be configured in some way to work with railway deployment? My next.config.js is specifies destination as:

source: '/api/:path*',
destination: 'http://localhost:8000/:path*',

and I've heard somewhere that it should be using a container's name instead of localhost, however, I know in railway things are not that simple. Do you have any advice there?

The waitress app is just run as:

if __name__ == "__main__":
    logger.debug("Starting Flask server")
    serve(app, host="0.0.0.0", port=8000)
Solved

5 Replies

a year ago

Hello,

You should be starting the next app and the flask app as two separate Railway services under the same project without any proxying.


Status changed to Awaiting User Response Railway over 1 year ago


piotrpomorski
PROOP

a year ago

but they are in the same repo, how should I do that? Before I ran fastapi plus next.js and I did not have ECONNREFUSED errors


Status changed to Awaiting Railway Response Railway over 1 year ago


a year ago

I'm assuming this would be an isolated monorepo, and in that case you would set the root directory in the service settings.

If it is not an isolated monorepo, you would want to convert the project into an isolated monorepo.


Status changed to Awaiting User Response Railway over 1 year ago


piotrpomorski
PROOP

a year ago

ok, so following this I guess would help: https://docs.railway.app/guides/monorepo#deploying-an-isolated-monorepo but then how would frontend know where backend is? i.e., localhost:8000 is enough?


Status changed to Awaiting Railway Response Railway over 1 year ago


a year ago

Your frontend would call the backends's public domain.


Status changed to Awaiting User Response Railway over 1 year ago


Railway
BOT

7 months ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway 7 months ago


Loading...