Skip to content

akoutmos/replug

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Replug

Hex.pm Build Status Coverage Status

Replug is a sister library for Unplug thats aims to provide the functionality that is out of scope for the Unplug library. Specifically, while Unplug allows you to conditionally execute Plugs, Replug allows you to configure arbitrary Plugs at run-time even if the Plugs don't directly support run-time configuration.

Installation

If available in Hex, the package can be installed by adding replug to your list of dependencies in mix.exs:

def deps do
  [
    {:replug, "~> 0.1.0"}
  ]
end

Usage

Replug can be used anywhere you would typically use the plug macro. For example, let's say you want to configure some non-configurable fields in Corsica, you could do the following:

# ---- router.ex ----
plug Replug,
  plug: {Corsica, expose_headers: ~w(X-Foo)},
  opts: {MyAppWeb.PlugConfigs, :corsica}

# ---- plug_configs.ex ----
defmodule MyAppWeb.PlugConfigs do
  def corsica do
    [
      max_age: System.get_env("CORSICA_MAX_AGE"),
      origins: System.get_env("VALID_ORIGINS")
    ]
  end
end

This will wrap the call to Corsica's Plug and manually invoke Corsica's init/1 function and it's call/2 function while providing run-time configuration.

About

Dynamically configure your Elixir Plugs at run-time

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages