Created
April 9, 2019 05:38
-
-
Save elorest/96b2636ab59fd57798fe5c301bd34449 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApiController < ApplicationController | |
def index | |
session[%w(a b c d e f g h i j k l m n o p).sample] = Time.now.to_s | |
respond_with do | |
json session.to_h.to_json | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Amber::Server.configure do | |
pipeline :web do | |
# Plug is the method to use connect a pipe (middleware) | |
# A plug accepts an instance of HTTP::Handler | |
# plug Amber::Pipe::PoweredByAmber.new | |
# plug Amber::Pipe::ClientIp.new(["X-Forwarded-For"]) | |
# plug Citrine::I18n::Handler.new | |
plug Amber::Pipe::Error.new | |
plug Amber::Pipe::Logger.new | |
plug Amber::Pipe::Session.new | |
plug Amber::Pipe::Flash.new | |
plug Amber::Pipe::CSRF.new | |
end | |
pipeline :api do | |
# plug Amber::Pipe::PoweredByAmber.new | |
plug Amber::Pipe::Error.new | |
plug Amber::Pipe::Logger.new | |
plug Amber::Pipe::Session.new | |
# plug Amber::Pipe::CORS.new | |
end | |
# All static content will run these transformations | |
pipeline :static do | |
plug Amber::Pipe::PoweredByAmber.new | |
plug Amber::Pipe::Error.new | |
plug Amber::Pipe::Static.new("./public") | |
end | |
routes :web do | |
resources "/animals", AnimalController | |
get "/", HomeController, :index | |
end | |
routes :api do | |
get "/api/animals", AnimalController, :index | |
get "/api/sessions", ApiController, :index | |
end | |
routes :static do | |
# Each route is defined as follow | |
# verb resource : String, controller : Symbol, action : Symbol | |
get "/*", Amber::Controller::Static, :index | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment