public networking is not available
nexblu
HOBBYOP

2 years ago

Excuse me sir, I'm trying to deploy a flask application, but the networking for public networking is not created, what is the cause, sir?

11 Replies

2 years ago

have you tried clicking generate domain?


nexblu
HOBBYOP

2 years ago

I am confused why there is no public networking on my flask application


nexblu
HOBBYOP

2 years ago

okey i try


nexblu
HOBBYOP

2 years ago

the result is like this sir

1280206407530057838


nexblu
HOBBYOP

2 years ago

{
    "$schema": "https://railway.app/railway.schema.json",
    "build": {
        "builder": "NIXPACKS"
    },
    "deploy": {
        "startCommand": "gunicorn main:app",
        "restartPolicyType": "ON_FAILURE",
        "restartPolicyMaxRetries": 10
    }
}```

my railway.json


nexblu
HOBBYOP

2 years ago

from flask import Flask
from flask_mongoengine import MongoEngine
from routes.license import license_router
from routes.user import user_router
from celery import Celery, Task
from models import LicenseModel
from configs import REDIS_URL, MONGODB_URL, DB_NAME


def celery_init_app(app: Flask) -> Celery:
    class FlaskTask(Task):
        def __call__(self, *args: object, **kwargs: object) -> object:
            with app.app_context():
                return self.run(*args, **kwargs)

    celery_app = Celery(app.name, task_cls=FlaskTask)
    celery_app.config_from_object(app.config["CELERY"])
    app.extensions["celery"] = celery_app
    return celery_app


db = MongoEngine()
app = Flask(__name__)
app.config["MONGODB_SETTINGS"] = {
    "db": DB_NAME,
    "host": MONGODB_URL,
}
db.init_app(app)

app.config.from_mapping(
    CELERY=dict(
        broker_url=REDIS_URL,
        result_backend=REDIS_URL,
        task_ignore_result=True,
    ),
)
celery_app = celery_init_app(app)


@celery_app.task
def background_task(data):
    import time

    time.sleep(data["duration"])
    if license := LicenseModel.objects(license=data["license"]).first():
        license.delete()
        return f'successfully deleted {data["license"]}'


@app.after_request
async def add_cors_headers(response):
    response.headers["Access-Control-Allow-Origin"] = "*"
    response.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS"
    response.headers["Access-Control-Allow-Headers"] = (
        "Content-Type, X-API-KEY, X-LICENSE"
    )
    return response


@app.route("/")
async def home():
    return "welcome to auto store api by nexblu store"


app.register_blueprint(license_router)
app.register_blueprint(user_router)

if __name__ == "__main__":
    app.run(debug=True, port=5000)```

my main.py code is like this


2 years ago

keyword: yet


nexblu
HOBBYOP

2 years ago

Sorry sir, what do you mean? I don't understand


imabdulazeez
PRO

2 years ago

Sorry to hijack the thread, just trying to help. Can you try adding PORT to the Variables of the service with the value of 5000. Redeploy and generate a new domain (or add a custom domain) that points to that port

I had this issue with Flask APIs and that did the trick


2 years ago

they don't even have a domain yet, but that's a simple single button press away


nexblu
HOBBYOP

2 years ago

okey thanks its work


Welcome!

Sign in to your Railway account to join the conversation.

Loading...