webhooksd/src/webhooksd.cr

36 lines
806 B
Crystal
Raw Normal View History

2020-11-26 14:51:57 +01:00
require "http/server"
require "option_parser"
VERSION = 0.1
port = 3000
OptionParser.parse do |parser|
parser.banner = "usage: webhooksd <scriptfile> [option]"
parser.on "-v", "--version", "Show version" do
puts "version #{VERSION}"
exit
end
parser.on "-h", "--help", "Show help" do
puts parser
exit
end
parser.on "-p PORT", "--port=PORT", "Port to listen for connections. Default: 3000" do |p|
port = p.to_i
end
end
server = HTTP::Server.new do |context|
2020-11-26 15:27:17 +01:00
pp context.request
if context.request.method != "POST" || context.request.path != "/"
context.response.status = HTTP::Status::NOT_FOUND
else
context.response.content_type = "text/plain"
context.response.print "Hello world! The time is #{Time.local}"
end
2020-11-26 14:51:57 +01:00
end
address = server.bind_tcp port
server.listen