diff --git a/Dockerfile.api b/Dockerfile.api deleted file mode 100644 index 25115a2..0000000 --- a/Dockerfile.api +++ /dev/null @@ -1,9 +0,0 @@ -FROM python:3.9 -WORKDIR /api - -COPY api/requirements.txt api/api.py ./ -RUN pip install -r ./requirements.txt -ENV FLASK_ENV production - -EXPOSE 5000 -CMD ["gunicorn", "-b", ":5000", "api:app"] \ No newline at end of file diff --git a/Dockerfile.client b/Dockerfile.client index d5a524e..cc5466a 100644 --- a/Dockerfile.client +++ b/Dockerfile.client @@ -2,7 +2,7 @@ FROM node:18 as build-step WORKDIR /frontend ENV PATH /frontend/node_modules/.bin:$PATH -COPY frontend/package.json frontend/yarn.lock frontend/tsconfig.json frontend/.env ./ +COPY frontend/package.json frontend/yarn.lock frontend/tsconfig.json ./ COPY frontend/src ./src COPY frontend/public ./public RUN yarn install @@ -11,4 +11,6 @@ RUN yarn build --production # Build step #2: build an nginx container FROM nginx:stable-alpine COPY --from=build-step /frontend/build /usr/share/nginx/html -COPY deployment/nginx.default.conf /etc/nginx/conf.d/default.conf \ No newline at end of file +COPY deployment/nginx.template /etc/nginx/nginx.template + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/api/.gitignore b/api/.gitignore deleted file mode 100644 index 68bc17f..0000000 --- a/api/.gitignore +++ /dev/null @@ -1,160 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ diff --git a/api/api.py b/api/api.py deleted file mode 100644 index e58db6a..0000000 --- a/api/api.py +++ /dev/null @@ -1,42 +0,0 @@ -from flask import Flask, request, jsonify -from flask_cors import CORS -import requests - -app = Flask(__name__) -CORS(app) - - -@app.route('/') -def root(): - return jsonify({'message': 'Welcome to the API!'}) - - -@app.route('/upload', methods=['POST']) -def upload(): - print(request.headers.get('Content-Type')) - if request.headers.get('Content-Type') == 'application/octet-stream': - bytes = request.data - base_url = request.headers.get('Base-Url') - auth_string = request.headers.get('Auth-String') - # print(request.data) - if auth_string is not None: - auth = tuple(auth_string.split(':')) - else: - auth = None - response = requests.post( - f'{base_url}/api/codex/v1/upload', - data=bytes, - headers={ - 'Content-Type': 'application/octet-stream' - }, - auth=auth - ) - print(response.status_code) - print(response.text) - return jsonify({'cid': response.text.strip()}) - else: - return jsonify({'message': 'Error!'}) - - -if __name__ == '__main__': - app.run(debug=True, host='0.0.0.0', port=5000) diff --git a/api/requirements.txt b/api/requirements.txt deleted file mode 100644 index 13ba1ba..0000000 --- a/api/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -requests -flask -gunicorn -flask-cors \ No newline at end of file diff --git a/deployment/nginx.default.conf b/deployment/nginx.default.conf deleted file mode 100644 index abe98f4..0000000 --- a/deployment/nginx.default.conf +++ /dev/null @@ -1,22 +0,0 @@ -server { - listen 80; - server_name localhost; - - root /usr/share/nginx/html; - index index.html; - error_page 500 502 503 504 /50x.html; - - location / { - try_files $uri /index.html; - add_header Cache-Control "no-cache"; - } - - location /static { - expires 1y; - add_header Cache-Control "public"; - } - - location /uploads { - proxy_pass http://localhost:5000; - } -} \ No newline at end of file diff --git a/deployment/nginx.template b/deployment/nginx.template new file mode 100644 index 0000000..85aaca7 --- /dev/null +++ b/deployment/nginx.template @@ -0,0 +1,21 @@ +server +{ + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + error_page 500 502 503 504 /50x.html; + + location /api { + proxy_pass $codex_url; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + location / { + try_files $uri /index.html; + add_header Cache-Control "no-cache"; + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 86082d7..020ea5d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,4 @@ services: - api: - build: - context: . - dockerfile: Dockerfile.api - image: codex-frontend-api - network_mode: "host" client: build: context: . @@ -12,3 +6,7 @@ services: image: codex-frontend-client ports: - "3000:80" + environment: + - codex_url=http://host.docker.internal:8080 + volumes: + - ./deployment/nginx.template:/etc/nginx/templates/10-variables.conf.template:ro \ No newline at end of file diff --git a/frontend/.env b/frontend/.env deleted file mode 100644 index 553b76f..0000000 --- a/frontend/.env +++ /dev/null @@ -1 +0,0 @@ -REACT_APP_CODEX_URL=http://localhost:8080 diff --git a/frontend/package.json b/frontend/package.json index edef1f7..3caa8a8 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -18,7 +18,6 @@ "@types/react": "^18.2.25", "@types/react-dom": "^18.2.11", "axios": "^1.5.1", - "dotenv": "^16.3.1", "form-data": "^4.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/frontend/src/pages/debug/DebugPage.tsx b/frontend/src/pages/debug/DebugPage.tsx index 0863b8a..c52af52 100644 --- a/frontend/src/pages/debug/DebugPage.tsx +++ b/frontend/src/pages/debug/DebugPage.tsx @@ -15,16 +15,13 @@ function DebugPage() { const [statusInfo, setStatusInfo] = React.useState< DebugNodeInfoModel | undefined >(); - useEffect(() => { axios .get( - `${ - nodeInfo.nodeToConnectTo || nodeInfo.baseUrl - }/api/codex/v1/debug/info`, + `/api/codex/v1/debug/info`, { headers: - (nodeInfo.auth !== null && { + (nodeInfo.auth && { Authorization: (nodeInfo.auth && "Basic " + btoa(nodeInfo.auth)) || "", }) || diff --git a/frontend/src/store.ts b/frontend/src/store.ts index 5bacbf8..19a17b2 100644 --- a/frontend/src/store.ts +++ b/frontend/src/store.ts @@ -28,7 +28,7 @@ export const useDexyStore = create()( ftdCid: "", setFtdCid: (cid) => set({ ftdCid: cid }), nodeInfo: { - baseUrl: process.env.REACT_APP_CODEX_URL || "http://localhost:8080", + baseUrl: "http://host.docker.internal:8080", nodeToConnectTo: null, id: null, // ip: null,