我有一个在localhost:5000中运行的调试器烧瓶api应用程序。api运行时没有问题。但是当我试图通过另一个应用程序使用它,我不能改变它,它使用localhost:5000/some_path。
我想从localhost:5000/some_path重定向到localhost:5000。
我已经读到我可以在我的烧瓶api应用程序中使用前缀,但我更喜欢另一种方法。我不想把密码搞砸。
是否有重定向/中间件或其他方式重定向此通信量?
docker-compose.yml:
# Use root/example as user/password credentials
version: "3.1"
services:
my-db:
image: mariadb
restart: always
environment:
MARIADB_ROOT_PASSWORD: example
ports:
- 3306:3306
volumes:
- ./0_schema.sql:/docker-entrypoint-initdb.d/0_schema.sql
- ./1_data.sql:/docker-entrypoint-initdb.d/1_data.sql
adminer:
image: adminer
restart: always
environment:
ADMINER_DEFAULT_SERVER: my-db
ports:
- 8080:8080
my-api:
build: ../my-awesome-api/
ports:
- 5000:5000发布于 2022-11-29 06:40:34
如果您使用web服务器为您的应用程序提供服务,您可以使用它来管理它,例如使用nginx您可以这样做:
location = /some_path {
return 301 /;
}或者您可以使用中间件:
class PrefixMiddleware(object):
def __init__(self, app, prefix=""):
self.app = app
self.prefix = prefix
def __call__(self, environ, start_response):
if environ["PATH_INFO"].startswith(self.prefix):
environ["PATH_INFO"] = environ["PATH_INFO"][len(self.prefix) :]
environ["SCRIPT_NAME"] = self.prefix
return self.app(environ, start_response)
else:
#handle not found然后通过添加前缀“忽略”来注册中间件。
app = Flask(__name__)
app.wsgi_app = PrefixMiddleware(biosfera_fe.wsgi_app, prefix="/some_path")https://stackoverflow.com/questions/74604160
复制相似问题