【发布时间】:2021-07-21 01:40:22
【问题描述】:
我有一个作为服务器文件夹的 sanic 应用程序,里面有 server.py 和 init.py。在 init.py 我有一行 import *
这是 server.py 的样子:
# server.py #
from sanic import Sanic
from sanic.response import json
class Bot:
def __init__(self):
self.app = Sanic("message-queue")
self.app.add_route(self._post, "/", methods=["POST"])
async def _post(self, request):
data = request.json
data1 = data["data1"]
data2 = data["data2"]
data3 = data["data3"]
def run(self, host="localhost", port=6778):
self.app.run(host, port)
并且在我导入 server.py 并运行它的服务器文件夹之外有一个主文件。
import os
from server import Server
from sanic import Sanic
if __name__ == "__main__":
server = Server()
server.run(host=os.getenv("HOST"), port=int(os.getenv("PORT")))
我通过这个简单的服务器接受一些 POST 请求并在控制台中打印它们。它在 localhost 中工作正常,但在 web 服务器中如果我运行它,我会得到 webservers localhost 地址,该地址不公开。我怎样才能把它暴露给公众?我尝试了几个小时,gunicorn,sanic 内置服务器,apache,nginx 一切但我失败了。我将不胜感激。
【问题讨论】:
标签: python python-3.x webserver wsgi sanic