Created
May 3, 2020 08:42
-
-
Save jonathandreyer/ba58877a4dbac8d8ec93abd4ecddf2a8 to your computer and use it in GitHub Desktop.
Catch all routes and data with flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from flask import Flask, request | |
import json | |
import logging | |
app = Flask(__name__) | |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
@app.route('/', defaults={'path': '/'}, methods=['GET', 'POST']) | |
@app.route('/<path:path>', methods=['GET', 'POST']) | |
def catch_all(path): | |
app.logger.debug('Path of request: ' + path) | |
try: | |
obj_json = json.loads(request.data) | |
app.logger.debug('Data of request: ' + json.dumps(obj_json)) | |
except: | |
pass | |
return json.dumps({'success': True}), 200, {'ContentType': 'application/json'} | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=9000, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment