Class: PicklesHttpServer
- Inherits:
-
Object
- Object
- PicklesHttpServer
- Defined in:
- lib/pickles_http.rb,
lib/pickles_http/utils.rb,
lib/pickles_http/logger.rb,
lib/pickles_http/router.rb,
lib/pickles_http/server.rb
Defined Under Namespace
Modules: Utils Classes: Logger, Router, Server
Instance Method Summary collapse
-
#add_route(method, path, handler) ⇒ Object
Method to add new route to PiclesServer.
-
#initialize(port: 8080, log_file: true, host: '127.0.0.1') ⇒ PicklesHttpServer
constructor
A new instance of PicklesHttpServer.
- #set_server_options(option, value) ⇒ Object
- #start ⇒ Object
- #use(middleware, custom_cors_headers = {}) ⇒ Object
Constructor Details
#initialize(port: 8080, log_file: true, host: '127.0.0.1') ⇒ PicklesHttpServer
Returns a new instance of PicklesHttpServer.
4 5 6 |
# File 'lib/pickles_http.rb', line 4 def initialize(port: 8080, log_file: true, host: '127.0.0.1') @socket = PicklesHttpServer::Server.new(port, log_file, host: host.to_s) end |
Instance Method Details
#add_route(method, path, handler) ⇒ Object
Method to add new route to PiclesServer
17 18 19 |
# File 'lib/pickles_http.rb', line 17 def add_route(method, path, handler) @socket.add_route(method, path, handler) end |
#set_server_options(option, value) ⇒ Object
26 27 28 |
# File 'lib/pickles_http.rb', line 26 def (option, value) @socket.change_server_option(option, value) end |
#start ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/pickles_http.rb', line 8 def start begin @socket.start() rescue Interrupt puts 'PicklesServer stopped by user, Bye 👋' end end |
#use(middleware, custom_cors_headers = {}) ⇒ Object
21 22 23 24 |
# File 'lib/pickles_http.rb', line 21 def use(middleware, custom_cors_headers = {}) middleware_parsed = Middlewares.Middleware_Parser.new(middleware, custom_cors_headers) @socket.use_middleware(middleware_parsed) end |