Skip to content
Snippets Groups Projects
Commit f2ae0a7b authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Return 404 when hitting invalid /api endpoints

parent ca9854f6
Branches
Tags
No related merge requests found
......@@ -11,7 +11,7 @@ Default Endpoints
"""
import pkg_resources
from flask import Blueprint, jsonify, render_template
from flask import Blueprint, jsonify, render_template, Response
from compendium_v2.routes import common
......@@ -45,6 +45,13 @@ def after_request(resp):
@routes.route('/', defaults={'path': ''}, methods=['GET'])
@routes.route('/<path:path>', methods=['GET'])
def index(path):
is_api = path.startswith('api')
if is_api:
# return 404 for API requests that don't match a route
return Response(status=404, mimetype='application/json', response='{"error": "Not Found"}')
# fallback to serving the SPA through index.html for all other requests
# https://flask.palletsprojects.com/en/2.0.x/patterns/singlepageapplications/
return render_template('index.html')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment