-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
128 lines (100 loc) · 3.3 KB
/
server.py
File metadata and controls
128 lines (100 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# from app import create_app
# Flask modules
from flask import Flask, render_template, send_from_directory
from werkzeug.serving import run_simple
from flask_bcrypt import Bcrypt
from app.extensions.responses import response_base
from flask_cors import CORS
from flask_jwt_extended import JWTManager
# Other modules
import os
def create_app(debug: bool = False):
# Check if debug environment variable was passed
FLASK_DEBUG = os.environ.get("FLASK_DEBUG", True)
if FLASK_DEBUG:
debug = FLASK_DEBUG
# Create the Flask application instance
app = Flask(
__name__,
template_folder="./templates",
static_folder="./static",
static_url_path="/",
)
CORS(app)
JWTManager(app)
# Set current_app context
app.app_context().push()
if debug:
from app.config.dev import DevConfig
app.config.from_object(DevConfig)
else:
from app.config.prod import ProdConfig
app.config.from_object(ProdConfig)
# Uncomment to enable logger
# from app.utils.logger import setup_flask_logger
# setup_flask_logger()
# Initialize extensions
from app.extensions import db
# print(db.db.ini)
db.db.init_app(app)
# Import all models and Create database tables
# from app import models
# db.create_all()
# Register blueprints or routes
# app.register_blueprint(auth)
# Global Ratelimit Checker
# this is used because auto_check is set to 'False'
# app.before_request(lambda: limiter.check())
return app
app = create_app(debug=True)
bcrypt = Bcrypt(app)
if __name__ == "__main__":
from app.routes.auth import *
from app.routes.property import *
from app.routes.buildings import *
from app.routes.master import *
from app.routes.rooms import *
from app.routes.guest import *
from app.routes.experience import *
from app.routes.rooms import *
from datetime import datetime
import pytz
FLUTTER_WEB_APP = "templates"
test = True
@app.route("/testupdate/")
def testupdate():
current_time = datetime.now(pytz.timezone('Asia/Calcutta'))
formatted_time = current_time.strftime('%H:%M:%S')
global test
test = formatted_time
return "HI"
@app.route("/teststatus/")
def teststatus():
global test
return str(test)
@app.route("/web/")
def render_page_web():
return render_template("/index.html")
@app.route("/web/<path:name>")
def return_flutter_doc(name):
datalist = str(name).split("/")
DIR_NAME = FLUTTER_WEB_APP
if len(datalist) > 1:
for i in range(0, len(datalist) - 1):
DIR_NAME += "/" + datalist[i]
return send_from_directory(DIR_NAME, datalist[-1])
@app.errorhandler(Exception)
def server_error(err):
app.logger.exception(err)
return response_base("Server Error", 500)
basedir = os.path.abspath(os.path.dirname(__file__))
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("SQLALCHEMY_DATABASE_URI")
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
# app.run()
run_simple(
application=app,
hostname=os.environ.get("BASE_IP", "0.0.0.0"),
port=int(os.environ.get("PORT")),
use_debugger=True,
use_reloader=True,
)