CrowdHailer / raxx

Interface for HTTP webservers, frameworks and clients
https://hexdocs.pm/raxx
Apache License 2.0
402 stars 29 forks source link

be able to make a stack of middleware #18

Closed CrowdHailer closed 7 years ago

CrowdHailer commented 7 years ago

I think there must be some great macro stuff possible here to reduce runtime lookups

defmodule MyApp do
  use Raxx.Stack

  stack Raxx.Csrf
  stack Raxx.Session, secret: "top secret"
  stack Raxx.GZip
  stack Raxx.Time
  stack Raxx.WhoAmI, server_name: "my name"
  stack Raxx.ContentLength
  stack Raxx.Head
  stack Raxx.Scrub, (redirect or rewrite)

  mount "/assets", AssetsController
  service "/accounts", "accounts.app.consul"
end
CrowdHailer commented 7 years ago
  def init(app, config) do

  end

  def handle_request(request, {next, methods}) do
    override_method(request, only: methods)
    |> next.handle_request
  end
  not_found = Raxx.NotFound
  router = {MyRouter, {not_found, config}}
  server = {Raxx.MethodOverride, {router, methods}}
  defmodule Server do
    use Raxx.Stack
    middleware Raxx.MethodOverride, [PUT, PATCH, DELETE]
    middleware MyRouter, config
    middleware
  end
  Ace.HTTP.start_link(server, port: port)
CrowdHailer commented 7 years ago

Can be done using make_overrideable examples are available in Tokumei