hashimotoa961 commited on
Commit
7f4c438
·
1 Parent(s): 1a856a8

1st commit

Browse files
Files changed (3) hide show
  1. DockerFile +8 -0
  2. app.py +30 -0
  3. requirements.txt +2 -0
DockerFile ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+ COPY ./requirements.txt /code/requirements.txt
5
+ COPY ./app.py /code/app.py
6
+
7
+ RUN pip install -r requirements.txt
8
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import requests
3
+
4
+ app = Flask(__name__)
5
+
6
+ @app.route('/', methods=['GET'])
7
+ def hello():
8
+ return 'Hello World!'
9
+
10
+ @app.route('/forward', methods=['GET'])
11
+ def api():
12
+ # クライアントからのリクエストデータを取得
13
+ endpoint = request.args.get('endpoint')
14
+ other_params = {key: value for key, value in request.args.items() if key != 'endpoint'}
15
+
16
+ if not endpoint:
17
+ return jsonify({'error': 'No endpoint specified'}), 400
18
+
19
+ # AWS API Gatewayにリクエストを転送
20
+ response = requests.get(endpoint, params=other_params)
21
+
22
+ # AWSからのレスポンスをクライアントに返す
23
+ return jsonify(response.json()), response.status_code
24
+
25
+
26
+
27
+ if __name__ == '__main__':
28
+ app.run(host='0.0.0.0', port=7860)
29
+
30
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Flask
2
+ requests