simthneoshj
commited on
Commit
•
b82fcd8
1
Parent(s):
181f8b5
Upload 3 files
Browse files- Dockerfile +17 -0
- app.py +39 -0
- requirements.txt +3 -0
Dockerfile
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 使用官方Python镜像作为基础镜像
|
2 |
+
FROM python:3.9
|
3 |
+
|
4 |
+
# 设置工作目录为/app
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# 将当前目录下的文件复制到工作目录中
|
8 |
+
COPY . /app
|
9 |
+
|
10 |
+
# 使用pip安装依赖
|
11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
12 |
+
|
13 |
+
# 告诉Docker容器在运行时监听哪个端口
|
14 |
+
EXPOSE 8080
|
15 |
+
|
16 |
+
# 运行app.py当容器启动时
|
17 |
+
CMD ["python", "./app.py"]
|
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import requests
|
3 |
+
import urllib3
|
4 |
+
from filelock import FileLock
|
5 |
+
|
6 |
+
urllib3.disable_warnings()
|
7 |
+
|
8 |
+
app = Flask(__name__)
|
9 |
+
|
10 |
+
def verify_register(url):
|
11 |
+
json_data = {
|
12 |
+
'name': 'jack',
|
13 |
+
'email': 'zdsdhddfjb@gamil.com',
|
14 |
+
'password': 'zxc1234d',
|
15 |
+
'confirm_password': 'zxc1234d',
|
16 |
+
}
|
17 |
+
|
18 |
+
try:
|
19 |
+
response = requests.post(f'{url}/api/auth/register', json=json_data, verify=False, timeout=15)
|
20 |
+
if response.status_code != 200:
|
21 |
+
return False, url
|
22 |
+
return True, url
|
23 |
+
|
24 |
+
except requests.exceptions.RequestException:
|
25 |
+
print(f'{url} 请求失败')
|
26 |
+
return False, url
|
27 |
+
|
28 |
+
@app.route('/', methods=['POST'])
|
29 |
+
def register():
|
30 |
+
req_data = request.get_json()
|
31 |
+
url = req_data.get('url')
|
32 |
+
success, url = verify_register(url)
|
33 |
+
if success:
|
34 |
+
return jsonify({'message': '注册成功', 'url': url}), 200
|
35 |
+
else:
|
36 |
+
return jsonify({'message': '注册失败或URL无法访问', 'url': url}), 400
|
37 |
+
|
38 |
+
if __name__ == '__main__':
|
39 |
+
app.run(host='0.0.0.0', port=8080, debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Flask
|
2 |
+
requests
|
3 |
+
filelock
|