From ed5924777de715278dd8f591fed5e10bf4be8208 Mon Sep 17 00:00:00 2001 From: Jaydin_MacBook Date: Thu, 11 Jan 2024 19:05:20 -0500 Subject: [PATCH] Updating Pathing and Ports --- backend/app.py | 11 ++++++++++- frontend/app.py | 7 +------ frontend/config.json | 6 ++++++ frontend/static/helpers.js | 14 ++++++++++++++ frontend/static/scripts.js | 5 ++++- 5 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 frontend/config.json create mode 100644 frontend/static/helpers.js diff --git a/backend/app.py b/backend/app.py index 3babe44..9a352b4 100644 --- a/backend/app.py +++ b/backend/app.py @@ -59,7 +59,16 @@ def clean_up_and_upload_files_to_google_drive(file_path=None): def authorize_drive(): - with open('settings.yaml', 'r') as file: + current_directory = os.getcwd() + + if 'backend' in current_directory: + settings_path = 'settings.yaml' + elif 'Archive-Me' in current_directory: + settings_path = 'backend/settings.yaml' + else: + raise Exception("Unable to locate settings file.") + + with open(settings_path, 'r') as file: settings = yaml.safe_load(file) settings['client_config']['client_id'] = os.environ.get('GOOGLE_CLIENT_ID') diff --git a/frontend/app.py b/frontend/app.py index 9317831..cfbfe95 100644 --- a/frontend/app.py +++ b/frontend/app.py @@ -1,4 +1,4 @@ -from flask import Flask, render_template, request, jsonify, send_from_directory, abort +from flask import Flask, render_template from flask_cors import CORS, cross_origin import os import logging @@ -28,11 +28,6 @@ def demo(): def directory(): return render_template('directory.html') -# Add a login route for demonstration -@app.route('/login', methods=['POST']) -def login(): - # Your login logic here - return jsonify(success=True) if __name__ == '__main__': app.run(host='0.0.0.0', port=app.config['PORT'], debug=app.config['DEBUG']) diff --git a/frontend/config.json b/frontend/config.json new file mode 100644 index 0000000..0e03787 --- /dev/null +++ b/frontend/config.json @@ -0,0 +1,6 @@ +{ + "apiUrl":{ + "dev":"http://localhost:5003", + "prod":"https://api.archive-me.net" + } +} \ No newline at end of file diff --git a/frontend/static/helpers.js b/frontend/static/helpers.js new file mode 100644 index 0000000..e115664 --- /dev/null +++ b/frontend/static/helpers.js @@ -0,0 +1,14 @@ +import config from 'frontend/config.json' + +function getEnv() { + if (!process.env) { + throw new Error('Process environment not found.'); + } + return process.env.ENVIRONMENT +} + +function getApiUrl() { + return config.apiUrl[getEnv()] +} + +export { getEnv, getApiUrl } \ No newline at end of file diff --git a/frontend/static/scripts.js b/frontend/static/scripts.js index a619196..cd776a7 100755 --- a/frontend/static/scripts.js +++ b/frontend/static/scripts.js @@ -1,3 +1,5 @@ +import { getApiUrl } from "./helpers"; + $(function () { // init feather icons feather.replace(); @@ -83,7 +85,8 @@ $(function () { const app = (() => { let fileKeyGlobal = null; let currentPath = ''; - const apiUrl = 'https://api.archive-me.net'; + + const apiUrl = getApiUrl(); const showLoadingScreen = () => { const loadingScreen = document.getElementById("loading-screen");