浏览代码

dockerfile add

Lehi4 2 年之前
父节点
当前提交
d4ab89b43c
共有 2 个文件被更改,包括 23 次插入0 次删除
  1. 9 0
      Dockerfile
  2. 14 0
      MAIN.py

+ 9 - 0
Dockerfile

@@ -0,0 +1,9 @@
+FROM python:3.10-slim
+
+
+RUN pip install --no-cache-dir --upgrade pip \
+  && pip install --no-cache-dir requests
+
+COPY main.py .
+CMD ["python3","./main.py"]
+EXPOSE 8000

+ 14 - 0
MAIN.py

@@ -1,5 +1,8 @@
+from datetime import datetime
 from http.server import HTTPServer, BaseHTTPRequestHandler
 
+import requests
+
 
 class HttpGetHandler(BaseHTTPRequestHandler):
     def do_GET(self):
@@ -28,6 +31,17 @@ class HttpGetHandler(BaseHTTPRequestHandler):
 
                 self.wfile.write(http_text.encode())
 
+            if self.path.endswith("/status"):
+                self.send_response(200)
+
+                self.send_header("Content-type", "text/html")
+                self.end_headers()
+                get = requests.get(url='https://api.ipify.org/')
+
+                http_text = f' <!doctype html><html><head><meta charset= utf-8><body>IP-адрес: {get.text}<br>Время: {datetime.now()}</body></html>'
+
+                self.wfile.write(http_text.encode())
+
         except IOError:
             self.send_error(400, f"File not found{self.path}")