Added rate limiting
This commit is contained in:
10
app.py
10
app.py
@ -7,6 +7,8 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from flask_limiter.util import get_remote_address
|
||||||
|
from flask_limiter import Limiter
|
||||||
import waitress.server
|
import waitress.server
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
@ -19,8 +21,15 @@ ACTION_MAP = {'shock': whspah.MODES.SHOCK,
|
|||||||
|
|
||||||
app = flask.Flask(__name__, static_folder='./www/')
|
app = flask.Flask(__name__, static_folder='./www/')
|
||||||
|
|
||||||
|
limiter = Limiter(
|
||||||
|
get_remote_address,
|
||||||
|
app=app,
|
||||||
|
storage_uri="memory://",
|
||||||
|
)
|
||||||
|
|
||||||
@app.route('/', defaults={'path': 'index.html'})
|
@app.route('/', defaults={'path': 'index.html'})
|
||||||
@app.route('/<path:path>')
|
@app.route('/<path:path>')
|
||||||
|
@limiter.exempt
|
||||||
def staticPage(path):
|
def staticPage(path):
|
||||||
"""
|
"""
|
||||||
Returns anything requested in the static folder.
|
Returns anything requested in the static folder.
|
||||||
@ -35,6 +44,7 @@ def staticPage(path):
|
|||||||
return flask.send_from_directory(app.static_folder, path)
|
return flask.send_from_directory(app.static_folder, path)
|
||||||
|
|
||||||
@app.route('/transmit', methods=['POST'], strict_slashes=False)
|
@app.route('/transmit', methods=['POST'], strict_slashes=False)
|
||||||
|
@limiter.limit("1/second")
|
||||||
def transmit():
|
def transmit():
|
||||||
"""
|
"""
|
||||||
Transmits the data contained within the POST request through WHSPAH.
|
Transmits the data contained within the POST request through WHSPAH.
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
Flask-Limiter
|
||||||
waitress
|
waitress
|
||||||
whspah
|
whspah
|
||||||
flask
|
flask
|
||||||
Reference in New Issue
Block a user