Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -1,47 +1,18 @@
|
|
1 |
-
from flask import Flask,
|
2 |
-
import requests
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
-
PROXY_TARGET = "https://gem-bingo.hf.space"
|
7 |
-
|
8 |
@app.route('/')
|
9 |
-
def
|
10 |
-
|
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'
|
21 |
-
def
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
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(
|
|
|
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()
|