Skip to content

Commit

Permalink
Update Spectator for Grip 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
grkek committed Nov 5, 2022
1 parent e1bc03c commit cddc636
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 30 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: spectator
version: 0.1.0
version: 0.2.0

authors:
- Giorgi Kavrelishvili <[email protected]>
Expand Down
30 changes: 1 addition & 29 deletions src/spectator.cr
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
module Grip
abstract class Application
def handlers : Array(HTTP::Handler)
handlers = [
@exception_handler,
@pipeline_handler,
@forward_handler,
@websocket_handler,
@http_handler,
] of HTTP::Handler

custom.each do |handler|
handlers.insert(handlers.size - 4, handler)
end

root.each do |handler|
handlers.insert(handlers.size - 2, handler)
end

{% if flag?(:serveStatic) %}
handlers.insert(1, @static_handler.not_nil!)
{% end %}

handlers
end
end
end

{% for method in %w(get post put head delete patch) %}
def {{method.id}}(application : Grip::Application, path : String, headers : HTTP::Headers? = nil, body : String? = nil)
io = IO::Memory.new
request = HTTP::Request.new("{{method.id}}".upcase, path, headers, body)
response = HTTP::Server::Response.new(io)

context = HTTP::Server::Context.new(request, response)
handlers = application.handlers
handlers = application.router

0.upto(handlers.size - 2) { |i| handlers[i].next = handlers[i + 1] }

Expand Down

0 comments on commit cddc636

Please sign in to comment.