diff --git a/docker-compose.yml b/docker-compose.yml index fcb4319..6e0db76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,27 +4,46 @@ services: nginx: image: nginx:latest volumes: - - ./conf/nginx.conf:/etc/nginx/nginx.conf - - ./logs/nginx:/etc/nginx/logs - - ./cert:/etc/nginx/cert + - ./frontend/conf/nginx.conf:/etc/nginx/nginx.conf + - ./frontend/logs/nginx:/etc/nginx/logs + - ./frontend/cert:/etc/nginx/cert networks: - net ports: - 80:80 + depends_on: + - server + + server: + container_name: server + build: frontend/backend + command: python -m flask run + ports: + - "4200:4200" + volumes: + - ./frontend/backend:/data/frontend/backend + - ./frontend/app.py:/data/frontend/app.py + - ./frontend/config.py:/data/frontend/config.py + environment: + - FLASK_APP=app.py + - FLASK_ENV=production + - FLASK_DEBUG=1 + - FLASK_RUN_PORT=4200 + - PYTHONUNBUFFERED=1 + networks: + - net + depends_on: + - frontend frontend: container_name: frontend - build: . - command: npm start - # ports: - # - "4200:4200" + build: frontend + command: npm run build volumes: - - ./src:/data/frontend - - ./node_modules:/data/frontend/node_modules + - ./frontend/src:/data/frontend + - ./frontend/node_modules:/data/frontend/node_modules environment: - NODE_ENV=production - networks: - - net networks: net: diff --git a/frontend/.gitignore b/frontend/.gitignore index bac05b4..350e08c 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -47,3 +47,5 @@ testem.log Thumbs.db package-lock.json + +backend/dist diff --git a/frontend/angular.json b/frontend/angular.json index 6dd4c96..9877372 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -20,7 +20,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/", + "outputPath": "backend/dist/", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", @@ -42,13 +42,13 @@ "budgets": [ { "type": "initial", - "maximumWarning": "500kb", - "maximumError": "1mb" + "maximumWarning": "1mb", + "maximumError": "2mb" }, { "type": "anyComponentStyle", - "maximumWarning": "2kb", - "maximumError": "4kb" + "maximumWarning": "4kb", + "maximumError": "8kb" } ], "fileReplacements": [ diff --git a/app.py b/frontend/app.py similarity index 50% rename from app.py rename to frontend/app.py index 2faec63..3f85513 100644 --- a/app.py +++ b/frontend/app.py @@ -1,7 +1,7 @@ -from . import create_app +from backend import create_app import os -app = create_app(os.environ.get('FLASK_ENV', None)) +app = create_app(os.environ.get('FLASK_ENV')) if __name__ == "__main__": app.run(host='0.0.0.0', DEBUG=True) diff --git a/Dockerfile b/frontend/backend/Dockerfile similarity index 66% rename from Dockerfile rename to frontend/backend/Dockerfile index 2987276..041b46d 100644 --- a/Dockerfile +++ b/frontend/backend/Dockerfile @@ -1,6 +1,7 @@ FROM python:latest -WORKDIR /data/backend +WORKDIR /data/frontend/backend COPY requirements.txt requirements.txt RUN pip install --upgrade pip RUN pip install -r requirements.txt -COPY . . \ No newline at end of file +COPY . . +WORKDIR /data/frontend diff --git a/__init__.py b/frontend/backend/__init__.py similarity index 100% rename from __init__.py rename to frontend/backend/__init__.py diff --git a/requirements.txt b/frontend/backend/requirements.txt similarity index 87% rename from requirements.txt rename to frontend/backend/requirements.txt index 1449498..887af13 100644 --- a/requirements.txt +++ b/frontend/backend/requirements.txt @@ -5,3 +5,4 @@ PyJWT==2.3.0 pytest==6.2.5 psycopg2==2.9.2 Flask-Cors==3.0.10 +requests==2.22.0 diff --git a/responses.py b/frontend/backend/responses.py similarity index 100% rename from responses.py rename to frontend/backend/responses.py diff --git a/routes.py b/frontend/backend/routes.py similarity index 98% rename from routes.py rename to frontend/backend/routes.py index e53ae17..cba8040 100644 --- a/routes.py +++ b/frontend/backend/routes.py @@ -1,6 +1,5 @@ from flask import request, Blueprint, send_from_directory, current_app as app import requests -import os from werkzeug.exceptions import HTTPException from .responses import send_message, send_error from .sessionJWT import create_auth_token, check_auth_token @@ -36,17 +35,17 @@ def handle_exception(e): @bp.route('/', methods=['GET']) def root(): - return send_from_directory("frontend/dist", "index.html") + return send_from_directory("dist", "index.html") -@bp.route('/frontend/dist/', methods=['GET']) +@bp.route('/frontend/backend/dist/', methods=['GET']) def static(path): - return send_from_directory("frontend/dist", path) + return send_from_directory("dist", path) @bp.route('/assets/', methods=['GET']) def assets(path): - return send_from_directory("frontend/dist/assets", path) + return send_from_directory("dist/assets", path) # Login diff --git a/sessionJWT.py b/frontend/backend/sessionJWT.py similarity index 100% rename from sessionJWT.py rename to frontend/backend/sessionJWT.py diff --git a/frontend/conf/nginx.conf b/frontend/conf/nginx.conf index 375380c..315d874 100644 --- a/frontend/conf/nginx.conf +++ b/frontend/conf/nginx.conf @@ -16,21 +16,21 @@ http { proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffers 32 4k; - - upstream frontend { - server frontend:4200; + + upstream server { + server server:4200; } server { listen 80; - server_name wordpress; + server_name flask-aled; access_log logs/access.log; location / { - proxy_pass http://frontend; + proxy_pass http://server; } } - -} \ No newline at end of file + +} diff --git a/config.py b/frontend/config.py similarity index 100% rename from config.py rename to frontend/config.py diff --git a/frontend/logs/nginx/access.log b/frontend/logs/nginx/access.log index 98ba7b7..7926e49 100644 --- a/frontend/logs/nginx/access.log +++ b/frontend/logs/nginx/access.log @@ -19,3 +19,17 @@ 192.168.16.1 - - [28/Jan/2022:11:04:23 +0000] "GET /styles.f64087845b474dd2.css HTTP/1.1" 304 0 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 OPR/82.0.4227.50" 192.168.16.1 - - [28/Jan/2022:11:04:23 +0000] "GET /assets/logo.png HTTP/1.1" 304 0 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 OPR/82.0.4227.50" 192.168.16.1 - - [28/Jan/2022:11:04:23 +0000] "GET /favicon.ico HTTP/1.1" 200 948 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 OPR/82.0.4227.50" +172.21.0.1 - - [01/Feb/2022:14:58:24 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.21.0.1 - - [01/Feb/2022:14:58:25 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.21.0.1 - - [01/Feb/2022:14:58:30 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.21.0.1 - - [01/Feb/2022:14:58:30 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://127.0.0.1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.21.0.1 - - [01/Feb/2022:15:01:07 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.21.0.1 - - [01/Feb/2022:15:01:07 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://127.0.0.1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.22.0.1 - - [01/Feb/2022:15:14:43 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.22.0.1 - - [01/Feb/2022:15:14:43 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://127.0.0.1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.22.0.1 - - [01/Feb/2022:15:19:49 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.22.0.1 - - [01/Feb/2022:15:19:52 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.22.0.1 - - [01/Feb/2022:15:22:17 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.22.0.1 - - [01/Feb/2022:15:22:18 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.22.0.1 - - [01/Feb/2022:15:22:19 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" +172.22.0.1 - - [01/Feb/2022:15:22:19 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" diff --git a/frontend/package.json b/frontend/package.json index 4337554..b347ace 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -3,8 +3,8 @@ "version": "0.0.0", "scripts": { "ng": "ng", - "start": "ng build && python flask run", - "build": "ng build --build-optimizer --baseHref=frontend/dist/", + "start": "ng build --build-optimizer --baseHref=frontend/backend/dist/ && cd .. && python -m flask run", + "build": "ng build --build-optimizer --baseHref=frontend/backend/dist/", "watch": "ng build --watch --configuration development", "test": "ng test" },