This repository was archived by the owner on Apr 21, 2019. It is now read-only.
This version introduces use
directive for Yeager::App
which allows one to use generic handlers for all routes. Following example will enable CORS
for all routes, currently use
does not support custom paths.
require "../src/yeager"
app = Yeager::App.new
app.get "/" do |req, res|
res.send "Hello world!"
end
app.post "/" do |_, res|
res.status(200).json({"Hello" => "world!"})
end
app.get "/:name" do |req, res|
res.send "Hello sub world! #{req.params["name"]}"
end
# Enable CORS
# Even though it's defined at the end this handler will be
# called before all the handlers. Multiple use handlers
# can be defined which will be called sequentially.
app.use do |req, res, continue|
res.headers.add "Access-Control-Allow-Origin", "*"
continue.call
end
# If you have a defined HTTP::Server already you can
# use app.handler after this point instead of running
# the server of the app.
app.listen 3000 do
print "Example app listening on 0.0.0.0:3000!"
end