from flask import send_from_directory, abort, make_response
import os.path as ospath
from functools import wraps


def expose_static_files(app):
    base_folder = ospath.abspath(ospath.join(ospath.dirname(__file__), '../../../../client/public/'))

    @app.route('/public/<path:path>')
    def send_static_files(path):
        print path
        try:
            return send_from_directory(base_folder, path)
        except:
            abort(404)


def no_cache(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        response = make_response(f(*args, **kwargs))
        response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
        response.headers['Pragma'] = 'no-cache'
        response.headers['Expires'] = '0'
        return response

    return decorated_function
