marshmallow-code / marshmallow-code/flask-smorest

flask-smorest with subdomains and redoc

Open
#661 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
717
Forks
77
Avg merge
7h 49m
Merged PRs (30d)
3

Description

I have this sample app

```py
from flask import Flask, jsonify
from flask_smorest import Api, Blueprint as SmorestBlueprint

# Initialize Flask app
app = Flask(__name__, subdomain_matching=True)
app.url_map.default_subdomain = "docs"
app.config["API_TITLE"] = "My API"
app.config["API_VERSION"] = "v1"
app.config["OPENAPI_VERSION"] = "3.0.2"
app.config["OPENAPI_URL_PREFIX"] = "/"
app.config["OPENAPI_REDOC_PATH"] = "/redoc"
app.config[
"OPENAPI_REDOC_URL"
] = "https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"
app.config[
"SERVER_NAME"
] = "example.com:5000" # Configure the server name to handle subdomains

# Initialize API
api = Api(app)

# Create 'account' and 'manage' blueprint
account_blp = SmorestBlueprint("account", "account")
manage_blp = SmorestBlueprint("manage", "manage")

@account_blp.route("/info", subdomain="account")
def account_info():
return jsonify({"message": "Account Info"})

@manage_blp.route("/settings", subdomain="manage")
def manage_settings():
return jsonify({"message": "Manage Settings"})

# Set up Redoc for each subdomain
redoc_html = """


Redoc





body {
margin: 0;
padding: 0;
}





"""

# Register blueprints with API
api.register_blueprint(account_blp, subdomain="account")
api.register_blueprint(manage_blp, subdomain="manage")

# print routes to see whats registered
for rule in app.url_map.iter_rules():
methods = ",".join(rule.methods)
print(f"{rule.endpoint:25s} {methods:20s} {rule.rule}")

if __name__ == "__main__":
# Run the app on all interfaces to accept requests from subdomains
app.run(debug=True, host="0.0.0.0", port=5000)

```

I added the entry below in `/etc/hosts`

```
127.0.0.1 account.example.com
127.0.0.1 manage.example.com
127.0.0.1 docs.example.com
```

- `http://account.example.com:5000/info` works
- `http://manage.example.com:5000/settings` works

`http://docs.example.com:5000/redoc` works but server URL for each endpoint is missing. Both endpoints starts with `http://docs.example.com:5000`

Contributor guide

Open the contributing guide

Research direction

Reproduce the sample application with Flask subdomain matching, the API configuration, and the account and manage blueprint registrations. Inspect the generated OpenAPI document and Redoc endpoint behavior; done means the documented endpoint server URLs preserve the appropriate subdomains instead of using docs.example.com for both.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, openapi, python
Domain
api, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.