From cec0f060c167eeac32693cd2d8c17fcd963e7f7b Mon Sep 17 00:00:00 2001 From: Giulio Date: Sun, 12 Dec 2021 10:43:28 +0100 Subject: [PATCH] making robots file optional --- Dockerfile | 2 ++ backend/__init__.py | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 401fabe..e87aa04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ WORKDIR /code COPY ./backend /code/ RUN pip install --user -r requirements.txt # We get the dependencies with the full python image so we can compile the one with missing binaries +ENV UseRobots=false FROM python:3.7.10-slim-stretch as app # copy the dependencies from the pybuilder @@ -20,4 +21,5 @@ COPY --from=pybuilder /code /dist COPY --from=builder ./dist /dist/ WORKDIR /dist EXPOSE 5001 + ENTRYPOINT ["python", "/dist/__init__.py"] diff --git a/backend/__init__.py b/backend/__init__.py index 0c78366..47df408 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -15,19 +15,35 @@ import sys sys.setrecursionlimit(10**6) # this should prevents bots from stopping sio = socketio.Server(cors_allowed_origins="*") -static_files={ - '/': {'content_type': 'text/html', 'filename': 'index.html'}, - '/game': {'content_type': 'text/html', 'filename': 'index.html'}, - '/help': {'content_type': 'text/html', 'filename': 'index.html'}, - '/status': {'content_type': 'text/html', 'filename': 'index.html'}, - # '/robots.txt': {'content_type': 'text/html', 'filename': 'robots.txt'}, - '/favicon.ico': {'filename': 'favicon.ico'}, - '/img/icons': './img/icons', - '/manifest.json': {'filename': 'manifest.json'}, - '/css': './css', - '/media': './media', - '/js': './js', -} +if "UseRobots" in os.environ and os.environ['UseRobots'].upper() == "TRUE": + static_files={ + '/': {'content_type': 'text/html', 'filename': 'index.html'}, + '/game': {'content_type': 'text/html', 'filename': 'index.html'}, + '/help': {'content_type': 'text/html', 'filename': 'index.html'}, + '/status': {'content_type': 'text/html', 'filename': 'index.html'}, + '/robots.txt': {'content_type': 'text/html', 'filename': 'robots.txt'}, + '/favicon.ico': {'filename': 'favicon.ico'}, + '/img/icons': './img/icons', + '/manifest.json': {'filename': 'manifest.json'}, + '/css': './css', + '/media': './media', + '/js': './js', + } +else: + static_files={ + '/': {'content_type': 'text/html', 'filename': 'index.html'}, + '/game': {'content_type': 'text/html', 'filename': 'index.html'}, + '/help': {'content_type': 'text/html', 'filename': 'index.html'}, + '/status': {'content_type': 'text/html', 'filename': 'index.html'}, + # '/robots.txt': {'content_type': 'text/html', 'filename': 'robots.txt'}, + '/favicon.ico': {'filename': 'favicon.ico'}, + '/img/icons': './img/icons', + '/manifest.json': {'filename': 'manifest.json'}, + '/css': './css', + '/media': './media', + '/js': './js', + } + for file in [f for f in os.listdir('.') if '.js' in f or '.map' in f or '.html' in f]: static_files[f'/{file}'] = f'./{file}'