Skip to content

Commit 60df5d6

Browse files
committed
Add error message when using GET for /graphql
Graphql expects a POST request so warn when client uses GET.
1 parent de852cc commit 60df5d6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn error::Error>> {
5656
let app = Router::new()
5757
.route("/graphql", post(graphql_handler))
5858
.route("/graphiql", get(graphiql_handler))
59+
.route(
60+
"/graphql",
61+
get((
62+
StatusCode::METHOD_NOT_ALLOWED,
63+
[("Allow", "POST")],
64+
Html(include_str!("../static/get_graphql_warning.html")),
65+
)),
66+
)
5967
.fallback((
6068
StatusCode::NOT_FOUND,
6169
Html(include_str!("../static/404.html")),

static/get_graphql_warning.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Glazed</title>
5+
</head>
6+
<body>
7+
<p>Requests should be made as graphql queries</p>
8+
</body>
9+
</html>

0 commit comments

Comments
 (0)