Questions tagged [plug]

Plug is a web application framework for Elixir.

An example of a Plug from the module documentation:

Hello World

defmodule MyPlug do
  import Plug.Conn

  def init(options) do
    # initialize options
    options
  end

  def call(conn, _opts) do
    conn
    |> put_resp_content_type("text/plain")
    |> send_resp(200, "Hello world")
  end
end

The snippet above shows a very simple example on how to use Plug. Save that snippet to a file and run it inside the plug application with:

iex -S mix
iex> c "path/to/file.ex"
[MyPlug]
iex> {:ok, _} = Plug.Cowboy.http MyPlug, []
{:ok, #PID<...>}
101 questions
0
votes
0 answers

Elixir redirect Http to Https

My app is responding properly to https://localhost, while http://localhost gives ERR_EMPTY_RESPONSE. http://localhost should be redirected to https://localhost. How can i obtain this in pure elixir? (no phoenix or such...). Some code has been…
Razinar
  • 727
  • 3
  • 13
  • 21
0
votes
1 answer

CSRF Protection in Phoenix and Angular

I have an Angular App for which i intend to use Phoenix as backend. Phoenix supports CSRF protection by default where the CSRF token is stored to session. This works fine when Phoenix is rendering views, but how do i get access to CSRF token when my…
0
votes
1 answer

What happens to a plug connection after it finishes the pipeline?

I am currently looking into Phoenix and i am wondering what happens to a plug connection after it finishes its plug pipeline. conn |> endpoint |> router |> controller |> view The documentation says, that the render/3 function will call the…
Luca Fülbier
  • 2,641
  • 1
  • 26
  • 43
0
votes
1 answer

Use assign from plug to view (elixir / phoenix)

I have my api pipeline in which I want to add a plug which basically does some operations in the database and based on the response it does an assign which I then use on my view. I´m having problems with passing the assign from the plug to the…
0
votes
1 answer

** (ArgumentError) flash not fetched, call fetch_flash/2

In my Phoenix app I have Plug that looks like this: defmodule MyApp.Web.Plugs.RequireAuth do import Plug.Conn import Phoenix.Controller import MyApp.Web.Router.Helpers def init(_options) do end def call(conn, _options) do if…
Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133
0
votes
1 answer

How to connect Plug.Router with Plug function

I'm trying to set up a very simple, basic HTTP API in Elixir. I thought using Phoenix for such a thing is totally overkill, so wanted to do it simply by using Plug. And I can do it by setting up a basic Router like this: defmodule Example.Router do …
ralh
  • 2,514
  • 1
  • 13
  • 19
0
votes
1 answer

'Cannot find memcached proc' error when running Phoenix app in Elixir

I am currently having a problem running the phoenix server application. This error is displayed when I tried to access 'localhost:4000'. It is complaining that it cannot find memcached proc on runtime as shown below. [error] #PID<0.558.0> running…
Sean T.
  • 1
  • 1
0
votes
0 answers

Using Elixir Plug.conn.assigns in multiple modules

My session_controller.ex in a Phoenix project assigns current_user and user_token to Conn as follows. def create(%Plug.Conn{private: %{openmaize_user: %{id: id}}} = conn, _params) do username = conn.private.openmaize_user.username …
Jason O.
  • 3,168
  • 6
  • 33
  • 72
-1
votes
0 answers

error: undefined function router/2 (expected MyApp.Endpoint to define such a function or for it to be imported, but none are available)

I have this elixir module: defmodule MyApp.Router do use Plug.Router plug :match plug :dispatch get "/" do send_resp(conn, 200, "Hello, World!") end end I run mix compile --no-halt and I get: % mix run --no-halt ===> Analyzing…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
-1
votes
2 answers

Plug.Conn, all plugs must receive a connection (conn) and return a connection

so I'm trying to update a schema by matching the params["state"] on a callback, In my controller, I'm doing something like this. def create(conn, params) do viewer = GiftActions.get_gift_user!(params["user_id"]) case params["state"] do …
copser
  • 2,523
  • 5
  • 38
  • 73
-1
votes
1 answer

Simple Elixir / Plug Processes Issue - PID not sticking around

I'm just starting out in Elixir and wanted to build a very simple API with Plug. I used this guide to get a very simple API up and running. Basically, the problem I'm facing is that the process that I registered as :qs doesn't seem to be found (and…
qarthandso
  • 2,100
  • 2
  • 24
  • 40
1 2 3 4 5 6
7