如何让一个Flask应用在两个不同的端口上监听? [英] How to have one Flask app listen on two different ports?

查看:844
本文介绍了如何让一个Flask应用在两个不同的端口上监听?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用一个烧瓶应用程序在两个不同的端口上路由?我的Flask应用程序需要侦听Webhook,并且由于某些安全事务,它无法在默认端口上接收外部POST请求.可以做这样的事情吗?

Is it possible to have a single flask app with routes on two different ports? My Flask app needs to listen for webhooks and due to some security biz it can't receive foreign POST requests on the default port. Is it possible to do something like this?

@app.route('/hook/<sourcename>', methods=["POST"], port=5051)
def handle_hook(sourcename):
  print 'asdf'

推荐答案

默认情况下,服务器仅侦听单个端口.因为额外的端口需要额外的功能,在第二个本地实现POST请求的端口上实现前端服务器,这是否更有意义? 有很多文献证明的方法,例如这种方法. a>

A server by default only listens to a single port. Wouldn't it make more sense, since the additional port requires additional functionality, to implement a front-end server on the second port that proxies the POST request locally? There are many well-documented ways to do this such as this one

这篇关于如何让一个Flask应用在两个不同的端口上监听?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆