Niansuh commited on
Commit
ec10aa4
·
verified ·
1 Parent(s): c14305d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -40
main.py CHANGED
@@ -1,47 +1,18 @@
1
- from flask import Flask, request, Response
2
- import requests
3
 
4
  app = Flask(__name__)
5
 
6
- PROXY_TARGET = "https://gem-bingo.hf.space"
7
-
8
  @app.route('/')
9
- def home():
10
- global PROXY_TARGET
11
- # Get the parameters of the original HTTP GET request
12
- resp = requests.get(f"{PROXY_TARGET}{request.full_path}")
13
- # Returns response data obtained from the target website
14
- excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
15
- headers = [(name, value) for (name, value) in resp.raw.headers.items()
16
- if name.lower() not in excluded_headers]
17
- response = Response(resp.content, resp.status_code, headers)
18
- return response
19
 
20
- @app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE'])
21
- def proxy(path):
22
- global PROXY_TARGET
23
- # Construct target URL
24
- url = f"{PROXY_TARGET}/{path}"
25
- # Send the corresponding request to the target server according to the original request method
26
- if request.method == 'GET':
27
- resp = requests.get(url, stream=True)
28
- elif request.method == 'POST':
29
- resp = requests.post(url, json=request.json, stream=True)
30
- elif request.method == 'PUT':
31
- resp = requests.put(url, json=request.json, stream=True)
32
- elif request.method == 'DELETE':
33
- resp = requests.delete(url, stream=True)
34
-
35
- # Return the response obtained from the target website to the client
36
- excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
37
- headers = [(name, value) for (name, value) in resp.raw.headers.items()
38
- if name.lower() not in excluded_headers]
39
-
40
- def generate():
41
- for chunk in resp.iter_content(chunk_size=8192):
42
- yield chunk
43
-
44
- return Response(generate(), resp.status_code, headers)
45
 
46
  if __name__ == '__main__':
47
- app.run(host='0.0.0.0', port=7860, debug=True)
 
1
+ from flask import Flask, redirect, abort, request
 
2
 
3
  app = Flask(__name__)
4
 
 
 
5
  @app.route('/')
6
+ def index():
7
+ return redirect('https://gem-bingo.hf.space', code=302)
 
 
 
 
 
 
 
 
8
 
9
+ @app.route('/<path:path>', methods=['GET', 'POST'])
10
+ def redirect_all(path):
11
+ if 'create' in path or 'fd' in path or 'web' in path:
12
+ return redirect('http://127.0.0.1', code=301)
13
+ if request.method == 'POST':
14
+ return redirect('http://127.0.0.1', code=301)
15
+ return redirect('https://gem-bingo.hf.space', code=302)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  if __name__ == '__main__':
18
+ app.run()