-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom converter for catch-all index path
#3045 fixed the 404 errors for non-existent urls but the implementation masks CORS issues with other endpoints. The catch-all index_pages endpoint , by default, has provide_automatic_options enabled and as a result it matches OPTIONS requests for non-existent urls or any other endpoints that have CORS incompletely configured. This makes it harder to debug CORS issues. To avoid this instead of throwing a 404 after matching, we need to throw the error during matching itself. Hence, use a custom path converter that matches all paths except those starting with the api prefix.
- Loading branch information
Showing
3 changed files
with
15 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from werkzeug.routing import PathConverter, ValidationError | ||
|
||
|
||
class NotApiPathConverter(PathConverter): | ||
|
||
def to_python(self, path): | ||
print(path) | ||
if path.startswith('1/'): | ||
raise ValidationError() | ||
return path |
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