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
1
vote
1 answer

Phoenix: How to test controller actions from the console?

I have created a new controller action and I would like to test it from the console to make sure it works. How can I execute the action after running iex -S mix phx.server in the terminal? It seems to me that in order to do this, I need to create a…
Erik Eng
  • 121
  • 7
1
vote
2 answers

Plug Parser: raising ParseError

I'm writing a Plug Parser that among other things decodes JSON using Poison (I'd prefer to let Plug.Parsers.JSON do that, but I need to read the raw request body to verify it against a signature, so that's not possible). I'm using Poison.decode/2 to…
Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
1
vote
0 answers

How to define different file upload limits for different controllers?

I have 2 pages in my Phoenix app, and they need different limits for the size of the file uploads (one page is fine with the default 8MB limit, but the second one needs a higher limit). From the docs, I can increase the limit in the MyApp.Endpoint…
Jakub Markos
  • 339
  • 3
  • 9
1
vote
0 answers

Elixir Plug configure for specific file

I have defined a plug in my App.Endpoint module in the following way: plug( Plug.Static, at: "/", from: :main_web, gzip: false, only: ~w(css fonts images webfonts favicon.ico robots.txt sw.js manifest.json js/app.js), headers:…
Sam Houston
  • 3,413
  • 2
  • 30
  • 46
1
vote
1 answer

Why does Elixir Plug compile plugs into AST using macro?

As the code https://github.com/elixir-plug/plug/blob/v1.5.0/lib/plug/builder.ex#L183 shows, plugs definition will be compiled to AST at macro expansion phase. But why? Why not just keep the plugs definition and use Enum.reduce_while or recursion to…
Tony Han
  • 2,130
  • 3
  • 24
  • 37
1
vote
1 answer

Elixir Plug gzip not working for pngs

I have plug Plug.Static, at: "/pros", from: :zipbooks, gzip: true, cache_control_for_etags: "public, max-age=604800", only: ~w(css assets fonts images js favicon.ico robots.txt) and my js css and svg files are being served with…
atomkirk
  • 3,701
  • 27
  • 30
1
vote
1 answer

parse json POST body

When using the following module definition defmodule Router.Folder do use Maru.Router namespace :folder do route_param :id do get do IO.puts "ID: " <> params[:id] json(conn, %{ user: params[:id], msg: "Hello Elixir…
bpmason1
  • 1,900
  • 1
  • 12
  • 9
0
votes
1 answer

How to use Application and Plug.Router to listen on port with Elixir

I have this Application file: defmodule MyApi do use Application def start(_type, _args) do children = [ MyApi.Router ] opts = [strategy: :one_for_one, name: MyApi.Supervisor] Supervisor.start_link(children, opts) …
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
0
votes
1 answer

How to stop Ajax cart button functionality from add to cart button

Plugin is WP Configurator Pro i want that the ajax add to cart button redirect to cart page. Tried this and many other examples but did not work add_action( 'wp_footer', 'trigger_for_ajax_add_to_cart' ); function trigger_for_ajax_add_to_cart() { ?>…
Pratiksha
  • 1
  • 1
0
votes
1 answer

no function clause matching in Plug controller

My function does not match in the controller My router: scope "/api", AtmAppWeb do pipe_through :api get "/index", UserAtmController, :index get "/show", UserAtmController, :show get "/get_founds", UserAtmController, :get_founds post…
0
votes
0 answers

Cowboy 2.9.0 reverse proxy websockets

I am a newer of elixir。I need to forward the websocket request from the cowboy sever http://127.0.0.1:4000/api to another server http://127.0.0.1:8080/abc. In short, how to implement reverse proxy websockets using Cowboy? The following is the…
0
votes
0 answers

Equation not viewing properly in tinymce editor

Integrated tinymce-equation-editor plugin in TinyMCE editor. When adding equation through the plugin window, it is not viewing properly in the TinyMCE editor. Eequation in plugin window Same equation when inserted in TinyMCE editor Tried adding…
Athira
  • 1
  • 1
0
votes
1 answer

How to stop further routing in a plug?

I'm using Phoenix, and in router.ex, I have defined a function that verifies the user's JWT token, before continuing on to routing through the api, in order to protect the routes. However, I am having the issue that if, say, I return a status of 403…
Basil
  • 488
  • 1
  • 15
0
votes
1 answer

wordpress access management articles

I have a question please, I would like to know if there is a plguin that allows you to manage access to articles according to the role. For example I have two categories (Questionnaire, surveys) and each category contains articles I want a user…
0
votes
1 answer

Creating a minimal Plug based http server in an exs file

I am trying to create a quick n dirty http server in an exs file that only sends the string 'Hello World'. Currently it's Mix.install([{:plug_cowboy, "~> 2.0"}]) defmodule HWPlug.Plug do import Plug.Conn def init(options), do: options …
Atul Vinayak
  • 466
  • 3
  • 15