def _init_ssl(self): import flask_sslify flask_sslify.SSLify(_app, permanent=True) if not (os.path.exists(self._certfile_path) and os.path.exists(self._keyfile_path)): self._create_self_signed_cert() WSGIServer.ssl_adapter = BuiltinSSLAdapter( certificate=self._certfile_path, private_key=self._keyfile_path)
import urlparse # Cache duration for snippets. # Since each page contains a link to the next one, even when no category is # selected, we risk users getting trapped circling among their cached pages # sometimes. We do depend on caching for prefetching to work, but let's do # it for only a short period to be safe. # An alternative would be to never cache when no category is selected UNLESS # when prefetching, but that's a bit more complex. CACHE_DURATION_SNIPPET = 30 app = flask.Flask(__name__) Compress(app) debug = 'DEBUG' in os.environ if not debug: flask_sslify.SSLify(app, permanent=True) Mobility(app) @app.route('/') @handlers.validate_lang_code def index(lang_code): pass # nothing to do but validate lang_code app.add_url_rule('/<lang_code>', view_func=handlers.citation_hunt) if 'stats' not in config.get_localized_config('en').flagged_off: app.add_url_rule('/<lang_code>/stats.html', view_func=handlers.stats) app.after_request(handlers.log_request) app.add_url_rule('/<lang_code>/search/category', view_func=handlers.search_category)
from backend.src.admin.api import admin_api from backend.src.app.api import app_api app = flask.Flask( __name__, static_folder="../../frontend/build/static", template_folder="../../frontend/build", ) # allow slash after endpoint app.url_map.strict_slashes = False # force HTTPS if "DYNO" in os.environ: sslify = flask_sslify.SSLify(app) # register sub-APIs app.register_blueprint(app_api, url_prefix="/api/app") app.register_blueprint(admin_api, url_prefix="/api/admin") @app.route("/api/test") def api_test(): return "Server is running! Good luck debugging :O" @app.route("/assets/<path:path>") def render_react_asset(path): return flask.send_from_directory("../../frontend/build/assets", path)
import textile import threading import functools import binascii import argparse import flask import flask_sse import flask_sslify import psutil application = flask.Flask(__name__) application.config['MAX_CONTENT_LENGTH'] = 9999999 application.secret_key = os.urandom(512) application.config["REDIS_URL"] = "redis://localhost:6379" application.register_blueprint(flask_sse.sse, url_prefix='/stream') flask_sslify.SSLify(application, permanent=True) CURRPATH = os.path.dirname(os.path.realpath(__file__)) NOAUTH = False SHAREDOBJECTPATH = '/dev/shm/shared.json' class backgroundexec(threading.Thread): ''' Background thread gère le redis ''' def __init__(self): threading.Thread.__init__(self) def run(self): with application.app_context():
if os.environ.has_key("DEBUG_EINIT"): app.debug = True app.config['CSRF_ENABLED'] = True #load databases app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', "sqllite://") #app.config['SQLALCHEMY_MIGRATE_REPO'] = os.path.join(os.path.abspath(os.path.split(os.path.dirname(__file__))[0]),'migrations') app.config['REDIS_URL'] = os.environ.get('REDISTOGO_URL') db = flask.ext.sqlalchemy.SQLAlchemy(app) #load secure token app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY') #other flask extensions sslify = flask_sslify.SSLify(app) #requires SSL bcrypt = flaskext.bcrypt.Bcrypt(app) #password digests bootstrap = flask_bootstrap.Bootstrap( app) #make bootstrap templates and helpers available. login_manager = flask.ext.login.LoginManager(app) #login manager redis = flask_redis.Redis(app) #redis #import models, views and helpers import einit.views import einit.models app.config['status_list'] = einit.models.status_list app.config['status_map'] = einit.models.status_details #set login manager options: login_manager.login_message_category = 'warning'