WIP setting up nginx to route correctly

This commit is contained in:
Shaun Orssaud 2023-11-01 20:12:20 +09:00
parent 30692fe0db
commit 34fc66b7d5
12 changed files with 44 additions and 258 deletions

View File

@ -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"]

View File

@ -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
EXPOSE 80
COPY deployment/nginx.conf /etc/nginx/conf.d/.conf
CMD ["nginx", "-g", "daemon off;"]

160
api/.gitignore vendored
View File

@ -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/

View File

@ -1,51 +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('/debug')
def debug():
base_url = request.headers.get('Base-Url')
response = requests.get(
f'{base_url}/api/codex/v1/debug/info'
)
print(response.status_code)
print(response.text)
return response.text
@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)

View File

@ -1,4 +0,0 @@
requests
flask
gunicorn
flask-cors

21
deployment/nginx.conf Normal file
View File

@ -0,0 +1,21 @@
events {}
http
{
server
{
listen 80;
server_name localhost;
location /api {
proxy_pass http://localhost:8080;
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";
}
}
}

View File

@ -1,18 +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";
}
}

View File

@ -1,11 +1,4 @@
services:
api:
build:
context: .
dockerfile: Dockerfile.api
image: codex-frontend-api
ports:
- "5000:5000"
client:
build:
context: .
@ -13,3 +6,14 @@ services:
image: codex-frontend-client
ports:
- "3000:80"
environment:
- CODEX=http://localhost:8080
nginx:
image: nginx:alpine
volumes:
- ./deployment/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "8070:80"
depends_on:
- client

View File

@ -1 +0,0 @@
REACT_APP_CODEX_URL=http://host.docker.internal:8080

View File

@ -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",

View File

@ -19,15 +19,18 @@ function DebugPage() {
useEffect(() => {
axios
.get(
`${constants.testApiBaseUrl}/debug`,
`/api/api/codex/v1/debug/info`,
{
headers:
({
"Base-Url": nodeInfo.baseUrl,
}),
(nodeInfo.auth && {
Authorization:
(nodeInfo.auth && "Basic " + btoa(nodeInfo.auth)) || "",
}) ||
{},
}
)
.then((response) => {
console.log(response.data);
setStatusInfo(
Convert.toDebugNodeInfoModel(JSON.stringify(response.data))
);

View File

@ -28,7 +28,7 @@ export const useDexyStore = create<DexyState>()(
ftdCid: "",
setFtdCid: (cid) => set({ ftdCid: cid }),
nodeInfo: {
baseUrl: process.env.REACT_APP_CODEX_URL || "http://localhost:8080",
baseUrl: "http://localhost",
nodeToConnectTo: null,
id: null,
// ip: null,