2023-06-17 11:38:50 +00:00
|
|
|
import platform
|
2023-09-26 12:00:17 +00:00
|
|
|
|
2023-02-15 18:40:23 +00:00
|
|
|
|
2023-02-03 12:45:29 +00:00
|
|
|
import dotenv
|
2023-09-27 15:25:57 +00:00
|
|
|
from application.celery import celery
|
2023-09-26 12:00:17 +00:00
|
|
|
from flask import Flask, request, redirect
|
|
|
|
|
2023-03-13 14:20:03 +00:00
|
|
|
|
2023-08-13 17:25:55 +00:00
|
|
|
from application.core.settings import settings
|
2023-09-26 09:03:22 +00:00
|
|
|
from application.api.user.routes import user
|
|
|
|
from application.api.answer.routes import answer
|
2023-09-27 15:25:57 +00:00
|
|
|
from application.api.internal.routes import internal
|
2023-06-17 10:40:28 +00:00
|
|
|
|
2023-08-15 13:14:49 +00:00
|
|
|
|
2023-02-15 18:40:23 +00:00
|
|
|
|
2023-02-05 13:24:01 +00:00
|
|
|
# Redirect PosixPath to WindowsPath on Windows
|
2023-02-15 18:40:23 +00:00
|
|
|
|
2023-02-05 13:24:01 +00:00
|
|
|
if platform.system() == "Windows":
|
|
|
|
import pathlib
|
2023-02-15 18:40:23 +00:00
|
|
|
|
2023-02-05 13:24:01 +00:00
|
|
|
temp = pathlib.PosixPath
|
|
|
|
pathlib.PosixPath = pathlib.WindowsPath
|
|
|
|
|
2023-02-03 12:45:29 +00:00
|
|
|
# loading the .env file
|
|
|
|
dotenv.load_dotenv()
|
|
|
|
|
2023-03-08 17:50:07 +00:00
|
|
|
|
2023-02-03 12:45:29 +00:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
2023-09-26 09:03:22 +00:00
|
|
|
app.register_blueprint(user)
|
|
|
|
app.register_blueprint(answer)
|
2023-09-27 15:25:57 +00:00
|
|
|
app.register_blueprint(internal)
|
2023-06-02 20:27:55 +00:00
|
|
|
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER = "inputs"
|
|
|
|
app.config["CELERY_BROKER_URL"] = settings.CELERY_BROKER_URL
|
|
|
|
app.config["CELERY_RESULT_BACKEND"] = settings.CELERY_RESULT_BACKEND
|
|
|
|
app.config["MONGO_URI"] = settings.MONGO_URI
|
2023-08-13 19:00:52 +00:00
|
|
|
celery.config_from_object("application.celeryconfig")
|
2023-03-13 14:20:03 +00:00
|
|
|
|
2023-05-12 10:02:25 +00:00
|
|
|
|
2023-04-03 13:37:09 +00:00
|
|
|
|
2023-02-03 12:45:29 +00:00
|
|
|
@app.route("/")
|
|
|
|
def home():
|
2023-09-07 08:19:58 +00:00
|
|
|
"""
|
|
|
|
The frontend source code lives in the /frontend directory of the repository.
|
|
|
|
"""
|
|
|
|
if request.remote_addr in ('0.0.0.0', '127.0.0.1', 'localhost', '172.18.0.1'):
|
|
|
|
# If users locally try to access DocsGPT running in Docker,
|
|
|
|
# they will be redirected to the Frontend application.
|
|
|
|
return redirect('http://localhost:5173')
|
|
|
|
else:
|
|
|
|
# Handle other cases or render the default page
|
|
|
|
return 'Welcome to DocsGPT Backend!'
|
2023-06-02 20:27:55 +00:00
|
|
|
|
2023-02-03 12:45:29 +00:00
|
|
|
|
2023-05-18 22:52:59 +00:00
|
|
|
|
|
|
|
|
2023-02-03 12:45:29 +00:00
|
|
|
# handling CORS
|
|
|
|
@app.after_request
|
|
|
|
def after_request(response):
|
2023-06-02 20:27:55 +00:00
|
|
|
response.headers.add("Access-Control-Allow-Origin", "*")
|
|
|
|
response.headers.add("Access-Control-Allow-Headers", "Content-Type,Authorization")
|
|
|
|
response.headers.add("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS")
|
2023-09-26 09:03:22 +00:00
|
|
|
# response.headers.add("Access-Control-Allow-Credentials", "true")
|
2023-02-03 12:45:29 +00:00
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-06-23 11:56:14 +00:00
|
|
|
app.run(debug=True, port=7091)
|