This repository was archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
60 lines (44 loc) · 1.45 KB
/
server.py
File metadata and controls
60 lines (44 loc) · 1.45 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
import ssl
import argparse
# logger
parser = argparse.ArgumentParser()
parser.add_argument("--logs", help="Set log level")
args = parser.parse_args()
from logger import baseLogger
baseLogger(args.logs or "info")
from config_init import configuration
config = configuration()
api = config["API"]
SSL = config["SSL_API"]
from flask import Flask
from flask_cors import CORS
from flask_swagger_ui import get_swaggerui_blueprint
from models.isSSL import isSSL
from routes.v1 import v1
from controllers.sync_database import create_database
from controllers.sync_database import create_tables
from controllers.sync_database import sync_products
app = Flask(__name__)
CORS(
app,
origins=api["ORIGINS"],
supports_credentials=True,
)
create_database()
create_tables()
sync_products()
swaggerui_blueprint = get_swaggerui_blueprint(
"/v1/api-docs", "/static/v1-api-docs.json"
)
app.register_blueprint(swaggerui_blueprint)
app.register_blueprint(v1, url_prefix="/v1")
checkSSL = isSSL(SSL["CERTIFICATE"], SSL["KEY"], SSL["PEM"])
if __name__ == "__main__":
if checkSSL:
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(SSL["CERTIFICATE"], SSL["KEY"])
app.logger.info("Running on secure port: %s" % SSL['PORT'])
app.run(host=api["HOST"], port=SSL["PORT"], ssl_context=context)
else:
app.logger.info("Running on un-secure port: %s" % api['PORT'])
app.run(host=api["HOST"], port=api["PORT"])