Skip to content

Instantly share code, notes, and snippets.

@jamesbeedy
Last active January 24, 2018 00:16
Show Gist options
  • Save jamesbeedy/8b6c02a398d3402ed13ad77d71ea0811 to your computer and use it in GitHub Desktop.
Save jamesbeedy/8b6c02a398d3402ed13ad77d71ea0811 to your computer and use it in GitHub Desktop.
import os
basedir = os.path.abspath(os.path.dirname(__file__))
APP_DIR = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.abspath(
os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir)
)
SECRETY_KEY = "b:h5AFz]3939sls55X;0g@P[{%"
DEBUG = os.getenv('DEBUG', False)
REDIS_URL="redis://someipaddress:6379/1"
from flask import (
Flask,
request
)
from flask_limiter import Limiter
# Configure application
app = Flask(__name__)
app.config.from_pyfile('config.py')
def get_api_key():
#key = request.headers.get('X-Api-Key')
#if key is None:
# key = request.args.get('api_key')
#if key is None:
# raise InvalidUsage(401)
return "mysecretkey"
limiter = Limiter(
app,
key_func=get_api_key,
headers_enabled=True,
strategy="fixed-window",
storage_uri=config.REDIS_URL
)
@app.route('/ping')
def ping():
return "pong"
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment