mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Well, this works
This commit is contained in:
parent
08993451e0
commit
860172916e
5 changed files with 35 additions and 17 deletions
12
royalnet/royalgamesweb.py
Normal file
12
royalnet/royalgamesweb.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import os
|
||||||
|
from .web import create_app
|
||||||
|
from .web.blueprints import helloworld
|
||||||
|
|
||||||
|
|
||||||
|
class TestConfig:
|
||||||
|
DB_PATH = os.environ["DB_PATH"]
|
||||||
|
REQUIRED_TABLES = set()
|
||||||
|
|
||||||
|
|
||||||
|
app = create_app(TestConfig, [helloworld.bp])
|
||||||
|
app.run()
|
|
@ -0,0 +1,3 @@
|
||||||
|
from .flaskserver import create_app
|
||||||
|
|
||||||
|
__all__ = ["create_app"]
|
|
@ -4,12 +4,12 @@ import werkzeug.local
|
||||||
|
|
||||||
def get_alchemy_session():
|
def get_alchemy_session():
|
||||||
if "alchemy_session" not in f.g:
|
if "alchemy_session" not in f.g:
|
||||||
f.g.alchemy_session = f.current_app.config["RN_ALCHEMY"].Session()
|
f.g.alchemy_session = f.g.alchemy.Session()
|
||||||
return f.g.alchemy_session
|
return f.g.alchemy_session
|
||||||
|
|
||||||
|
|
||||||
@f.current_app.teardown_appcontext
|
@f.current_app.teardown_appcontext
|
||||||
def teardown_alchemy_session(*args, **kwargs):
|
def teardown_alchemy_session(*_, **__):
|
||||||
_alchemy_session = f.g.pop("alchemy_session", None)
|
_alchemy_session = f.g.pop("alchemy_session", None)
|
||||||
if _alchemy_session is not None:
|
if _alchemy_session is not None:
|
||||||
_alchemy_session.close()
|
_alchemy_session.close()
|
||||||
|
|
9
royalnet/web/blueprints/helloworld.py
Normal file
9
royalnet/web/blueprints/helloworld.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import flask as f
|
||||||
|
|
||||||
|
|
||||||
|
bp = f.Blueprint("helloworld", __name__, url_prefix="/helloworld")
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/")
|
||||||
|
def helloworld():
|
||||||
|
return "Hello world!"
|
|
@ -1,19 +1,13 @@
|
||||||
|
import typing
|
||||||
import flask as f
|
import flask as f
|
||||||
import os
|
|
||||||
from ..database import Alchemy
|
from ..database import Alchemy
|
||||||
|
|
||||||
|
|
||||||
app = f.Flask(__name__)
|
def create_app(config_obj: typing.Type, blueprints: typing.List[f.Blueprint]):
|
||||||
app.config["RN_ALCHEMY"] = Alchemy(os.environ["DB_PATH"], set())
|
app = f.Flask(__name__)
|
||||||
with app.app_context():
|
app.config.from_object(config_obj)
|
||||||
from .alchemyhandler import alchemy_session as db_session
|
with app.app_context():
|
||||||
|
f.g.alchemy = Alchemy(app.config["DB_PATH"], app.config["REQUIRED_TABLES"])
|
||||||
|
for blueprint in blueprints:
|
||||||
@app.route("/")
|
app.register_blueprint(blueprint)
|
||||||
def test():
|
return app
|
||||||
...
|
|
||||||
return repr(db_session)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app.run()
|
|
||||||
|
|
Loading…
Reference in a new issue