cbf74585 |
from flask import Flask, g, request, session
|
40eb88e8 |
from flask_limiter import Limiter
|
cbf74585 |
from flask.ext.login import login_required
|
e7b832f1 |
import os
import base64
from marrow import database
from marrow import user
from marrow import bone
|
6d06b19d |
app = Flask(__name__)
|
e7b832f1 |
app.teardown_appcontext(database.close_connection)
|
cbf74585 |
# app.config["APPLICATION_ROOT"] = "/api"
|
e7b832f1 |
|
422508c9 |
try:
|
e2e8ff94 |
from marrow_config import config
|
422508c9 |
except ImportError:
|
e2e8ff94 |
class config:
secret_key = base64.b64encode(os.urandom(24))
debug = False
|
cbf74585 |
static_root = os.path.join(os.path.dirname(__file__), os.path.pardir, 'static')
|
0cb9217d |
server_name = "localhost"
|
422508c9 |
|
e2e8ff94 |
app.secret_key = config.secret_key
app.debug = config.debug
|
0cb9217d |
app.config["SERVER_NAME"] = config.server_name
|
e7b832f1 |
|
40eb88e8 |
limiter = Limiter(app)
limiter.limit("60/hour 3/second", key_func=lambda: request.host)(user.user_blueprint)
|
66cad4fc |
limiter.exempt(user.checkuser)
|
b608c416 |
limiter.exempt(user.following)
|
a2217c42 |
limiter.exempt(user.follows)
|
40eb88e8 |
|
e7b832f1 |
# Blueprints #
|
b3203439 |
user.login_manager.init_app(app)
|
e7b832f1 |
user.get_users(app)
app.register_blueprint(user.user_blueprint, url_prefix='/user')
app.register_blueprint(bone.bone_blueprint, url_prefix='/bones')
|
44c65b1c |
@app.route('/root')
def get_index_page():
filebase = 'index'
if 'username' not in session:
filebase = 'login'
filename = os.path.join(config.static_root, '%s.html' % filebase)
with open(filename) as f:
return f.read()
|
6d06b19d |
@app.route('/')
|
cbf74585 |
def index():
|
44c65b1c |
filename = os.path.join(config.static_root, 'index.html')
|
cbf74585 |
with open(filename) as f:
dat = f.read()
return dat
|
6d06b19d |
if __name__ == '__main__':
app.run(host='0.0.0.0')
|