From f6343beab1263ca57c505ebb8d6dd1bee01362b2 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Wed, 23 Nov 2022 11:54:25 -0500 Subject: [PATCH] Inform requesters that they likely forgot to add a path if they hit `https:///` (#29) --- webhook.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/webhook.py b/webhook.py index 0a8aced..b9464af 100644 --- a/webhook.py +++ b/webhook.py @@ -15,7 +15,7 @@ import logging from typing import Dict -from flask import Flask +from flask import Flask, request from github import Github from github.Repository import Repository from github_webhook import Webhook @@ -40,7 +40,7 @@ def __init__( self.repo = repo self.command_handler = CommandHandler(config, store, repo) - # Start a flash webserver + # Start a flask webserver self.app = Flask(__name__) webhook = Webhook( @@ -49,9 +49,15 @@ def __init__( secret=self.config.webhook_secret, ) - @self.app.route("/") - def hello_world(): - return "Hello, world!" + @self.app.route("/", methods=["GET", "POST"]) + def invalid_path_route(path): + """Respond to a request on an unrecognised HTTP method + path combination.""" + # We never expect a GET. + if request.method != "POST": + return "This application only responds to POST requests", 405 + + # The requester used a POST, but didn't use the configured webhook URL. + return "Did you forget to use the configured webhook path? :)", 404 @webhook.hook("issue_comment") def on_issue_comment(data):