【发布时间】:2021-11-24 18:51:15
【问题描述】:
我不知道什么是微不足道的问题:
我有一个 dockerized FastAPI 服务。它由 2 个容器组成:serviceA 和 serviceB。
我希望 serviceB 仅对 serviceA 可用,而不是对全世界可用。
我试过这个:
from fastapi.middleware.trustedhost import TrustedHostMiddleware
def get_application():
app = FastAPI(title=server_config.PROJECT_NAME, version=server_config.VERSION)
app.add_middleware( TrustedHostMiddleware, allowed_hosts=["http://serviceA"] )
return app
# Connect to DB
app = get_application()
但它不起作用,来自 serviceA 的请求被阻止。我也尝试了 localhost、serviceA:8000 等,但没有任何效果...
有什么想法吗?
【问题讨论】: