-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.rb
41 lines (31 loc) · 1003 Bytes
/
server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# cargamos todos las clases, modulos etc de lib, controllers y models
Dir[File.dirname(__FILE__) + '/lib/*.rb'].each {|file| require file }
Dir[File.dirname(__FILE__) + '/app/controllers/*.rb'].each {|file| require file }
Dir[File.dirname(__FILE__) + '/app/models/*.rb'].each {|file| require file }
require 'webrick'
include WEBrick
s = HTTPServer.new(:Port => 3000)
class MyServlet < HTTPServlet::AbstractServlet
def do_GET(request, response)
puts ""
puts "-------------------------------------"
params = Router.get_params(request)
logger(params)
response.body = Dispatcher.dispatch(params)
response['Content-Type'] = "text/html"
end
alias :do_POST :do_GET
def logger(params)
string_params = "{ "
params.each { |k,v| string_params << ":#{k} => '#{v}', " }
string_params = string_params[0..-3]
string_params << " } "
puts string_params
end
end
LoadModels.load_models
s.mount("/", MyServlet)
trap("INT"){
s.shutdown
}
s.start