From 482271b737851b3e71005df1e914b21b46c17148 Mon Sep 17 00:00:00 2001 From: icyleaf Date: Fri, 7 Dec 2018 14:34:42 +0800 Subject: [PATCH 1/2] fix http server snippet with crystal 0.27 --- snippets/crystal.json | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/snippets/crystal.json b/snippets/crystal.json index 4e6af40..63a869a 100644 --- a/snippets/crystal.json +++ b/snippets/crystal.json @@ -2,21 +2,25 @@ "HTTP simple server": { "prefix": "http server", "body": [ - "server = HTTP::Server.new(${1:\"0.0.0.0\"}, ${2:8080}) do |context|", - "\tcontext.response.content_type = \"text/plain\"", - "\tcontext.response.print \"Hello world!\"", - "end" + "server = HTTP::Server.new do |context|", + "\tcontext.response.content_type = \"text/plain\"", + "\tcontext.response.print \"Hello world!\"", + "end", + "\nserver.bind_tcp ${1:\"0.0.0.0\"}, ${2:8080}", + "server.listen" ], "description": "HTTP Server example." }, "HTTP server with handlers": { "prefix": "http server with handlers", "body": [ - "HTTP::Server.new(${1:\"127.0.0.1\"}, ${2:8080}, [", - "\tHTTP::ErrorHandler.new,", - "\tHTTP::LogHandler.new,", - "\tHTTP::StaticFileHandler.new(\".\"),", - "]).listen" + "server = HTTP::Server.new([", + "\tHTTP::ErrorHandler.new,", + "\tHTTP::LogHandler.new,", + "\tHTTP::StaticFileHandler.new(\".\"),", + "])", + "\nserver.bind_tcp ${1:\"0.0.0.0\"}, ${2:8080}", + "server.listen" ], "description": "HTTP Server example with error, logs and static handler." }, From 1c3e5116419bd11445aaca9b2bdccdb41b11f052 Mon Sep 17 00:00:00 2001 From: icyleaf Date: Fri, 7 Dec 2018 14:34:58 +0800 Subject: [PATCH 2/2] add http handler snippet --- snippets/crystal.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/snippets/crystal.json b/snippets/crystal.json index 63a869a..c882785 100644 --- a/snippets/crystal.json +++ b/snippets/crystal.json @@ -24,6 +24,19 @@ ], "description": "HTTP Server example with error, logs and static handler." }, + "HTTP handler": { + "prefix": "http handler", + "body": [ + "class ${1:HTTPHandler}", + "\tinclude HTTP::Handler", + "", + "\tdef call(context)", + "\t\t$0", + "\tend", + "end" + ], + "description": "HTTP Handler example." + }, "Exception block": { "prefix": "begin", "body": [