from flask import Flask, render_template, request import logging from flask_cors import CORS as cors logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) app = Flask(__name__) from os.path import join, exists, isdir from os import listdir, makedirs import re from labeler.config import DATA_MAP as data_map, DEFAULT_DATASET as default_dataset, LIMIT_PER_PAGE as limit cors(app) @app.route('/') def index(): dataset = request.args.get('dataset', default_dataset) return render_template(f'{dataset}.html') @app.route('/data', methods=['GET', 'POST']) def data(): dataset = request.args.get('dataset', default_dataset) page = int(request.args.get('page', 1)) # find, filter, sort, slice files = list(listdir(join('datasets', dataset)))
uri = secretKeys.CONNECTION_STRING client = MongoClient(uri) # Init Flask App app = Flask(__name__) app.config['DEBUG'] = True app.config['SESSION_COOKIE_HTTPONLY'] = False app.config['SESSION_REFRESH_EACH_REQUEST'] = False app.secret_key = 'mysecret' cors(app, resources={r"*": { "origins": "*" }}, headers=['Content-Type'], expose_headers=['Access-Control-Allow-Origin'], supports_credentials=True) # Init MongoDB Connection and run sample query to test authentication app.config["MONGO_URI"] = uri mongo = PyMongo(app) # Now that app is initialized, import other paths # Import all get requests # Index #global booleans that will keep track of errors wrongPassword = False nonexistentUser = False existentUser = False
import os import connexion # type: ignore from flask_cors import CORS as cors # type: ignore import logging from dotenv import load_dotenv import warnings from pandas.core.common import SettingWithCopyWarning # type: ignore # Wait for openfisca-core upgrade : from openfisca_core.warnings import OpenFiscaMemoryWarning, OpenFiscaTempfileWarning # type: ignore logging.basicConfig(level=logging.INFO) con = connexion.App("server", specification_dir=".") con.add_api("api.yaml") app = con.app cors(app, origins="*") if __name__ == "__main__": load_dotenv(dotenv_path=".env") # Do we have to remove warning ? if os.environ.get("IGNORE_WARNING") == "yes": logging.warning('--- All SettingWithCopyWarning warnings from Pandas will be ignored ---') warnings.simplefilter(action="ignore", category=SettingWithCopyWarning) # Wait for openfisca-core upgrade : warnings.simplefilter(action="ignore", category=OpenFiscaMemoryWarning) # Wait for openfisca-core upgrade : warnings.simplefilter(action="ignore", category=OpenFiscaTempfileWarning) con.run(host=os.environ.get("HOST"), port=os.environ.get("PORT"))
config['MongoDB']['URI'] = environ['MONGO_URI'] with open('config.ini', 'w') as configfile: config.write(configfile) else: # else, read form config.ini config.read('config.ini') # Init Flask App app = Flask(__name__) app.config['DEBUG'] = True app.config['SESSION_COOKIE_HTTPONLY'] = False app.config['SESSION_REFRESH_EACH_REQUEST'] = False cors(app, origins=["http://localhost:3000"], headers=['Content-Type'], expose_headers=['Access-Control-Allow-Origin'], supports_credentials=True) # Init MongoDB Connection and run sample query to test authentication app.config["MONGO_URI"] = config['MongoDB']['URI'] try: mongo = PyMongo(app) list(mongo.db.users.find({}).limit(1)) except ConfigurationError as err: if (err.args[0] == "A DNS label is empty."): print( "[ERROR]: MongoDB URI returning SRV error. If you're on the FSUSecure" ) print( " network, we recommend using the expanded URI to circumvent"
from core.config import API_PORT, API_HOST from flask_cors import CORS as cors from backend.api.routes import * from backend.api import app # from flask import Flask # app = Flask(__name__) if __name__ == "__main__": cors(app) app.run(port=API_PORT, host=API_HOST)