cloudscraper / Dockerfile
edwagbb's picture
Update Dockerfile
4c3e52e verified
FROM python:3-slim
EXPOSE 7860
RUN pip install cloudscraper Flask --upgrade && \
apt-get update -y && \
apt-get install -y nodejs libnode108 && \
rm -rf /var/lib/apt/lists/*
COPY <<EOF /main.py
from flask import Flask, request, Response
import cloudscraper
scraper = cloudscraper.create_scraper(interpreter='nodejs')
app = Flask(__name__)
@app.route('/proxy/<scheme>:/<path:url>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
def proxy(scheme, url):
req_method = request.method
req_headers = {key: value for key, value in request.headers if key != 'Host'}
req_data = request.get_data()
resp = scraper.request(method=req_method,
url=f'{scheme}://{url}',
headers=req_headers,
data=req_data,
stream=True)
excluded_headers = [] #['content-encoding', 'content-length', 'transfer-encoding', 'connection']
headers = [(name, value) for (name, value) in resp.raw.headers.items()
if name.lower() not in excluded_headers]
def generate():
for chunk in resp.iter_content(chunk_size=1):
yield chunk
return Response(generate(), status=resp.status_code, headers=headers)
@app.route('/', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
@app.route('/<path:url>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
def cf(url=""):
req_method = request.method
req_headers = {key: value for key, value in request.headers if key != 'Host'}
req_data = request.get_data()
resp = scraper.request(method=req_method,
url=f'https://chat.freegpts.org/{url}',
headers=req_headers,
data=req_data,
stream=True)
excluded_headers = [] #['content-encoding', 'content-length', 'transfer-encoding', 'connection']
headers = [(name, value) for (name, value) in resp.raw.headers.items()
if name.lower() not in excluded_headers]
def generate():
for chunk in resp.iter_content(chunk_size=1):
yield chunk
return Response(generate(), status=resp.status_code, headers=headers)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860)
EOF
CMD python /main.py