Skip to content

Commit

Permalink
Basic rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromechoo committed Oct 27, 2023
1 parent c8098ea commit 965fb9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
from dotenv import load_dotenv
from feedgen.feed import FeedGenerator
from flask import Flask, request, make_response, render_template
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address

app = Flask(__name__)

load_dotenv()
DIFFBOT_TOKEN = os.getenv("DIFFBOT_TOKEN", None)

# Really basic rate limiting to avoid taking down the app by bad actors
limiter = Limiter(
get_remote_address,
app=app,
storage_uri='memory://'
)

@app.route('/')
def index():
return render_template('home.html')

@app.route('/rss')
@limiter.limit("1/second", error_message='Rate limit exceeded')
def rss():

# 1. Extract list from URL
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
feedgen
Flask
requests
Flask-Limiter
gunicorn
python-dotenv
gunicorn
requests

0 comments on commit 965fb9e

Please sign in to comment.