Skip to content

Commit

Permalink
Addition of HTTPS support (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
KasKatto authored Jul 6, 2023
1 parent cf4d858 commit 0982b4c
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/action-controller/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class ActionController::Server
@socket = HTTP::Server.new(BEFORE_HANDLERS + [route_handler] + AFTER_HANDLERS)
end

# create an instance of the application with tls
def initialize(@ssl_context : OpenSSL::SSL::Context::Server?, @port = 3000, @host = "127.0.0.1", @reuse_port = true)
@processes = [] of Future::Compute(Nil)
init_routes
@socket = HTTP::Server.new(BEFORE_HANDLERS + [route_handler] + AFTER_HANDLERS)
end

private def init_routes
{% for klass in ActionController::Base::CONCRETE_CONTROLLERS %}
{{klass}}.__init_routes__(self)
Expand All @@ -57,14 +64,26 @@ class ActionController::Server

# Starts the server, providing a callback once the ports are bound
def run(&)
@socket.bind_tcp(@host, @port, @reuse_port) if @socket.addresses.empty?
if @socket.addresses.empty?
if ssl_context = @ssl_context
@socket.bind_tls(@host, @port, ssl_context, @reuse_port)
else
@socket.bind_tcp(@host, @port, @reuse_port)
end
end
yield
@socket.listen
end

# Starts the server
def run
@socket.bind_tcp(@host, @port, @reuse_port) if @socket.addresses.empty?
if @socket.addresses.empty?
if ssl_context = @ssl_context
@socket.bind_tls(@host, @port, ssl_context, @reuse_port)
else
@socket.bind_tcp(@host, @port, @reuse_port)
end
end
"Listening on #{print_addresses}"
@socket.listen
end
Expand Down

0 comments on commit 0982b4c

Please sign in to comment.