Browse Source

Fixed the failing build of the Grip framework (#6068)

* Fixed the failing build of the Grip framework

* Fixed the issue with the JWT shard, 1.4.2 uses Crystal 0.35.1

* Disable logging in the framework
Giorgi Kavrelishvili 4 years ago
parent
commit
7c8e4a0404
2 changed files with 55 additions and 60 deletions
  1. 49 58
      frameworks/Crystal/grip/grip.cr
  2. 6 2
      frameworks/Crystal/grip/shard.yml

+ 49 - 58
frameworks/Crystal/grip/grip.cr

@@ -5,19 +5,6 @@ require "ecr/macros"
 APPDB      = DB.open(ENV["DATABASE_URL"])
 ID_MAXIMUM = 10_000
 
-module Grip
-  module DSL
-    module Methods
-       def html(context, content, status_code = HTTP::Status::OK)
-        context.response.status_code = status_code.to_i
-        context.response.headers.merge!({"Content-Type" => "text/html; charset=UTF-8"})
-        context.response.print(content)
-        context.response
-      end
-    end
-  end
-end
-
 private def random_world
   id = rand(1..ID_MAXIMUM)
   id, random_number = APPDB.query_one("SELECT id, randomNumber FROM world WHERE id = $1", id, as: {Int32, Int32})
@@ -45,71 +32,72 @@ private def sanitized_query_count(request)
   queries.clamp(1..500)
 end
 
-class Json < Grip::Controller::Http
+class Json < Grip::Controllers::Http
   def get(context)
-    context.response.headers["Server"] = "Grip"
-    context.response.headers["Date"] = HTTP.format_time(Time.utc)
-    json(
-      context,
-      {
-        message: "Hello, World!",
-      }
-    )
+    context
+      .put_resp_header("Server", "Grip")
+      .put_resp_header("Date", HTTP.format_time(Time.utc))
+      .json(
+        {
+          message: "Hello, World!",
+        }
+      )
   end
 end
 
-class Plaintext < Grip::Controller::Http
+class Plaintext < Grip::Controllers::Http
   def get(context)
-    context.response.headers["Server"] = "Grip"
-    context.response.headers["Date"] = HTTP.format_time(Time.utc)
-    text(
-      context,
-      "Hello, World!"
-    )
+    context
+      .put_resp_header("Server", "Grip")
+      .put_resp_header("Date", HTTP.format_time(Time.utc))
+      .text(
+        "Hello, World!"
+      )
   end
 end
 
-class Db < Grip::Controller::Http
+class Db < Grip::Controllers::Http
   def get(context)
-    context.response.headers["Server"] = "Grip"
-    context.response.headers["Date"] = HTTP.format_time(Time.utc)
-    json(
-      context,
-      random_world
-    )
+    context
+      .put_resp_header("Server", "Grip")
+      .put_resp_header("Date", HTTP.format_time(Time.utc))
+      .json(
+        random_world
+      )
   end
 end
 
-class Queries < Grip::Controller::Http
+class Queries < Grip::Controllers::Http
   def get(context)
     results = (1..sanitized_query_count(context.request)).map do
       random_world
     end
 
-    context.response.headers["Server"] = "Grip"
-    context.response.headers["Date"] = HTTP.format_time(Time.utc)
-    json(
-      context,
-      results
-    )
+    context
+      .put_resp_header("Server", "Grip")
+      .put_resp_header("Date", HTTP.format_time(Time.utc))
+      .json(
+        results
+      )
   end
 end
 
-class Updates < Grip::Controller::Http
+class Updates < Grip::Controllers::Http
   def get(context)
     updated = (1..sanitized_query_count(context.request)).map do
       set_world({id: random_world[:id], randomNumber: rand(1..ID_MAXIMUM)})
     end
-    context.response.headers["Server"] = "Grip"
-    context.response.headers["Date"] = HTTP.format_time(Time.utc)
-    json(
-      context,
-      updated
-    )
+
+    context
+      .put_resp_header("Server", "Grip")
+      .put_resp_header("Date", HTTP.format_time(Time.utc))
+      .json(
+        updated
+      )
   end
 end
 
-class Fortunes < Grip::Controller::Http
+class Fortunes < Grip::Controllers::Http
   def get(context)
     data = fortunes
     additional_fortune = {
@@ -119,15 +107,15 @@ class Fortunes < Grip::Controller::Http
     data.push(additional_fortune)
     data.sort_by! { |fortune| fortune[:message] }
 
-    context.response.headers["Server"] = "Grip"
-    context.response.headers["Date"] = HTTP.format_time(Time.utc)
-
     io = IO::Memory.new
     ECR.embed "views/fortunes.ecr", io
-    html(
-      context,
-      io.to_s
-    )
+
+    context
+      .put_resp_header("Server", "Grip")
+      .put_resp_header("Date", HTTP.format_time(Time.utc))
+      .html(
+        io.to_s
+      )
   end
 end
 
@@ -143,6 +131,9 @@ class Application < Grip::Application
 end
 
 app = Application.new
+
+Grip.config.logging = false
+
 app.run(8080) do |config|
   server = config.server.not_nil!
   server.bind_tcp "0.0.0.0", 8080, reuse_port: true

+ 6 - 2
frameworks/Crystal/grip/shard.yml

@@ -4,11 +4,15 @@ version: 0.1.0
 dependencies:
   grip:
     github: grip-framework/grip
+
+  jwt:
+    github: crystal-community/jwt
+    version: 1.4.1
+
   pg:
     github: will/crystal-pg
     version: 0.20.0
+
 targets:
   grip:
     main: grip.cr
-
-crystal: 0.34.0