Skip to content

Commit 6b85ac7

Browse files
committed
version 3.8.0.1 update
修复使用外部web服务器运行带来的BUG
1 parent 2a88a73 commit 6b85ac7

File tree

9 files changed

+24
-8
lines changed

9 files changed

+24
-8
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ COPY . /opt
66
VOLUME ["/opt/logs"]
77
EXPOSE 5000
88
RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r /opt/requirements.txt
9-
RUN pip3 install Flask-SSM==3.8.0.0
9+
RUN pip3 install Flask-SSM==3.8.0.1
1010
# 启动
1111
CMD python3 ./app.py

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,7 @@ class Pojo:
417417
<tr>
418418
<td>3.8.0.0</td><td>集成Flask-Pydantic,现在可以使用type&nbsp;hints对API及SQL的参数类型进行校验</td><td>2024年7月31日</td>
419419
</tr>
420+
<tr>
421+
<td>3.8.0.1</td><td>修复使用外部web服务器运行带来的BUG</td><td>2024年8月2日</td>
422+
</tr>
420423
</table>

app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99

1010
if __name__ == '__main__':
1111
app.run()
12+
else:
13+
app.run_with_outside_server()

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
docker build -t zongxr/flask-ssm-example:3.8.0.0 .
2+
docker build -t zongxr/flask-ssm-example:3.8.0.1 .
33
python3 setup.py sdist bdist_wheel
44
python3 -m twine upload --repository testpypi dist/*
55
python3 -m twine upload dist/*

flask_ssm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# -*- coding: utf-8 -*-
22

33

4-
__version__ = "3.8.0.0"
4+
__version__ = "3.8.0.1"

flask_ssm/springframework/boot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import os
33
from typing import List, Optional
4-
from types import ModuleType
4+
from types import ModuleType, MethodType
55
import inspect
66
import pkgutil
77
import logging
@@ -16,7 +16,7 @@
1616
from flask_ssm.springframework.stereotype import Controller, Service, Repository
1717
from flask_ssm.springframework.context.annotation import Configuration, Bean
1818
from flask_ssm.springframework.scheduling.annotation import Scheduled
19-
from flask_ssm.utils.module_utils import walk_sub_modules
19+
from flask_ssm.utils.module_utils import walk_sub_modules, run_with_outside_server
2020
from flask_ssm.utils.context_utils import add_app_context
2121
from flask_ssm.utils.type_utils import pojo_private_properties
2222

@@ -213,4 +213,5 @@ def run(*args, **kwargs):
213213
mounts = None if app.config.get("APPLICATION_ROOT", "/") == "/" else {app.config.get("APPLICATION_ROOT", "/"): app}
214214
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, mounts=mounts)
215215
app.run = run
216+
app.run_with_outside_server = MethodType(run_with_outside_server, app)
216217
app.logger.info("初始化运行入口成功")

flask_ssm/utils/module_utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import List, Optional, Union, Tuple, Any
55
from types import ModuleType, FunctionType, LambdaType
66
import inspect
7-
from flask import Blueprint
7+
from flask import Blueprint, Flask
88

99

1010
def walk_sub_modules(package: ModuleType) -> List[ModuleType]:
@@ -101,3 +101,13 @@ def blueprint_from_module(func: FunctionType) -> Blueprint:
101101
)
102102
setattr(_module_, "__blueprint__", result)
103103
return result
104+
105+
106+
def run_with_outside_server(self: Flask, server_name: Optional[str] = None) -> None:
107+
"""
108+
使用外部web服务器运行时的必要设置\n
109+
:param self: Flask对象
110+
:param server_name: 服务器软件名称,暂未使用
111+
"""
112+
for _, bp in self.blueprints.items():
113+
bp.root_path = os.getcwd()

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ pydantic~=2.0
1010
typing-inspect~=0.8.0;python_version=="3.7"
1111
APScheduler==3.10.4
1212
Werkzeug>=2.1.2,<=2.3.8
13-
setuptools~=65.5.0
13+
setuptools

run_with_docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22
mkdir -p /opt/flask-ssm-example/logs
3-
docker run -d -p 5000:5000 -v /opt/flask-ssm-example/logs:/opt/logs zongxr/flask-ssm-example:3.8.0.0
3+
docker run -d -p 5000:5000 -v /opt/flask-ssm-example/logs:/opt/logs zongxr/flask-ssm-example:3.8.0.1

0 commit comments

Comments
 (0)