This commit is contained in:
Yûki VACHOT 2022-01-31 16:15:40 +01:00
parent bc62ef4f0d
commit a18333c2c3
101 changed files with 54 additions and 59 deletions

View file

@ -1,6 +1,6 @@
FROM node:latest
WORKDIR /app-frontend
COPY ["package.json", "package-lock.json*", "./"]
RUN npm install
RUN npm install -g @angular/cli
COPY . .
FROM python:latest
WORKDIR /data/backend
COPY requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
COPY . .

View file

@ -1,16 +1,12 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS
import sys
db = SQLAlchemy()
def create_app(flask_env='development'):
app = Flask(__name__, instance_relative_config=False)
app = Flask(__name__, instance_relative_config=False, static_url_path='')
origin = app.config.get('ALLOW_ORIGIN')
if origin is None:
origin = ['http://127.0.0.1:4200', 'http://localhost:4200']
origin = ['http://127.0.0.1:5000', 'http://localhost:5000']
CORS(app, supports_credentials=True, origins=origin)
if flask_env == 'production':
app.config.from_object("config.ProductionConfig")
@ -21,15 +17,7 @@ def create_app(flask_env='development'):
else:
app.config.from_object("config.Config")
if app.config['SQLALCHEMY_DATABASE_URI_1'] is None or app.config['SQLALCHEMY_DATABASE_URI_2'] is None:
print('No ENV Variable for DATABASE_URL_USERS or DATABASE_URL_LOGS')
sys.exit(1)
else:
print('ENV Variables passed : ', app.config['SQLALCHEMY_BINDS'])
db.init_app(app)
with app.app_context():
from . import routes
app.register_blueprint(routes.bp)
db.create_all()
return app

7
app.py Normal file
View file

@ -0,0 +1,7 @@
from . import create_app
import os
app = create_app(os.environ.get('FLASK_ENV', None))
if __name__ == "__main__":
app.run(host='0.0.0.0', DEBUG=True)

View file

@ -1,6 +0,0 @@
FROM python:latest
WORKDIR /data/backend
COPY requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
COPY . .

View file

@ -1,8 +0,0 @@
from application import create_app
import os
app = create_app(os.environ.get('FLASK_ENV', None))
if __name__ == "__main__":
PORT = os.environ.get('PORT', 33507)
app.run(host='0.0.0.0', port=PORT, DEBUG=True)

View file

@ -1,13 +0,0 @@
alembic==1.7.5
Flask==2.0.2
Flask-Migrate==3.1.0
Flask-Script==2.0.6
Flask-Testing==0.8.1
Flask-SQLAlchemy==2.5.1
Flask-WTF==0.15.1
pipreqs==0.4.10
PyJWT==2.3.0
pytest==6.2.5
SQLAlchemy==1.4.27
psycopg2==2.9.2
Flask-Cors==3.0.10

View file

@ -10,6 +10,7 @@ class Config(object):
FLASK_APP = os.environ.get('FLASK_APP', None)
FLASK_ENV = os.environ.get('FLASK_ENV', None)
FLASK_RUN_PORT = os.environ.get('FLASK_RUN_PORT', 4200)
API_URL = os.environ.get('API_URL', 'http://127.0.0.1:5000/api/')

View file

@ -15,3 +15,5 @@ last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.
not ios_saf 15.2-15.3
not safari 15.2-15.3

View file

6
frontend/Dockerfile Normal file
View file

@ -0,0 +1,6 @@
FROM node:latest
WORKDIR /app-frontend
COPY ["package.json", "package-lock.json*", "./"]
RUN npm install
RUN npm install -g @angular/cli
COPY . .

View file

@ -20,7 +20,7 @@
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "backend/static",
"outputPath": "dist/",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",

View file

@ -3,8 +3,8 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng build --prod --build-optimizer --baseHref=”/static/” && node server.js",
"build": "ng build --prod --build-optimizer --baseHref=”/static/”",
"start": "ng build && python flask run",
"build": "ng build --build-optimizer --baseHref=frontend/dist",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},

View file

Before

Width:  |  Height:  |  Size: 197 KiB

After

Width:  |  Height:  |  Size: 197 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Before After
Before After

View file

@ -1,4 +1,4 @@
export const environment = {
production: true,
debutUrl: 'http://127.0.0.1:5000/api/'
debutUrl: 'http://127.0.0.1:4200/api/'
};

View file

@ -5,7 +5,7 @@
export const environment = {
production: false,
debutUrl: 'http://127.0.0.1:5000/api/'
debutUrl: 'http://127.0.0.1:4200/api/'
};
/*

View file

Before

Width:  |  Height:  |  Size: 948 B

After

Width:  |  Height:  |  Size: 948 B

Before After
Before After

7
requirements.txt Normal file
View file

@ -0,0 +1,7 @@
Flask==2.0.2
Flask-Testing==0.8.1
Flask-WTF==0.15.1
PyJWT==2.3.0
pytest==6.2.5
psycopg2==2.9.2
Flask-Cors==3.0.10

View file

@ -1,28 +1,29 @@
from flask import request, Blueprint, render_template, current_app as app
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
import requests
from .sessionJWT import create_auth_token, check_auth_token
# Request Post
def request_post(url, data_json):
return requests.post(app.config['SQLALCHEMY_BINDS'] + url, json=data_json)
return requests.post(app.config['API_URL'] + url, json=data_json)
# Request Put
def request_put(url, data_json):
return requests.put(app.config['SQLALCHEMY_BINDS'] + url, json=data_json)
return requests.put(app.config['API_URL'] + url, json=data_json)
# Request Get
def request_get(url):
return requests.get(app.config['SQLALCHEMY_BINDS'] + url)
return requests.get(app.config['API_URL'] + url)
# Request Delete
def request_delete(url, data_json):
return requests.delete(app.config['SQLALCHEMY_BINDS'] + url, json=data_json)
return requests.delete(app.config['API_URL'] + url, json=data_json)
bp = Blueprint('myapp', __name__)
@ -35,7 +36,17 @@ def handle_exception(e):
@bp.route('/', methods=['GET'])
def root():
return render_template('index.html')
return send_from_directory("frontend/dist", "index.html")
@bp.route('/frontend/dist/<path:path>', methods=['GET'])
def static(path):
return send_from_directory("frontend/dist", path)
@bp.route('/assets/<path:path>', methods=['GET'])
def assets(path):
return send_from_directory("frontend/dist/assets", path)
# Login

Some files were not shown because too many files have changed in this diff Show more