43 lines
1.0 KiB
Python
43 lines
1.0 KiB
Python
|
import os
|
||
|
from flask import Flask, render_template
|
||
|
from pathlib import Path
|
||
|
from .auth import login_required
|
||
|
|
||
|
|
||
|
DATABASE_NAME = "kanken_online.sqlite"
|
||
|
def create_app(test_config=None):
|
||
|
app = Flask(__name__, instance_relative_config=True)
|
||
|
app.config.from_mapping(
|
||
|
SECRET_KEY="dev",
|
||
|
DATABASE=str(Path(app.instance_path) / DATABASE_NAME)
|
||
|
)
|
||
|
|
||
|
if test_config is None:
|
||
|
app.config.from_pyfile("config.py", silent=True)
|
||
|
else:
|
||
|
app.config.from_mapping(test_config)
|
||
|
|
||
|
# Ensure instance path exists
|
||
|
os.makedirs(app.instance_path, exist_ok=True)
|
||
|
|
||
|
@app.route("/hello")
|
||
|
def hello():
|
||
|
return "Hello, World!"
|
||
|
|
||
|
@app.route("/")
|
||
|
def index():
|
||
|
return render_template("index.html")
|
||
|
|
||
|
@app.route("/options")
|
||
|
@login_required
|
||
|
def options():
|
||
|
return "options"
|
||
|
|
||
|
from . import database
|
||
|
database.initialize_app(app)
|
||
|
|
||
|
from . import auth, api
|
||
|
app.register_blueprint(auth.blueprint)
|
||
|
app.register_blueprint(api.blueprint)
|
||
|
|
||
|
return app
|