feat:将两个接口端口分离

This commit is contained in:
kaku 2024-07-06 16:50:37 +08:00
parent ad761407b7
commit 6af0a0bbf9
2 changed files with 29 additions and 11 deletions

View File

@ -1,6 +1,7 @@
[server]
port=8080
debug=1
port-web=8080
port-api=8081
debug=0
host=0.0.0.0
threaded=1

35
main.py
View File

@ -1,6 +1,7 @@
from flask import Flask
import app_conf
import threading
from web.api.receive import api_receive_bp
from web.page import page_bp
@ -9,15 +10,31 @@ from web.page import page_bp
conf = app_conf.conf()
app = Flask(__name__)
app.register_blueprint(page_bp)
app.register_blueprint(api_receive_bp)
def runapp1():
app1 = Flask(__name__)
app1.register_blueprint(page_bp)
app1.run(
debug=conf.getboolean("server", "debug"),
host=conf.get("server", "host"),
port=conf.get("server", "port-web"),
threaded=conf.getboolean("server", "threaded"),
)
def runapp2():
app2 = Flask(__name__)
app2.register_blueprint(api_receive_bp)
app2.run(
debug=conf.getboolean("server", "debug"),
host=conf.get("server", "host"),
port=conf.get("server", "port-api"),
threaded=conf.getboolean("server", "threaded"),
)
if __name__ == "__main__":
app.run(
debug=conf.getboolean("server", "debug"),
host=conf.get("server", "host"),
port=conf.get("server", "port"),
threaded=conf.getboolean("server", "threaded"),
)
thread1 = threading.Thread(target=runapp1)
thread2 = threading.Thread(target=runapp2)
thread1.start()
thread2.start()