Skip to content

zampino/pastelli_phoenix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pastelli.Phoenix

Let Phoenix Framework run over the Elli server through Pastelli plug adapter and elli_websocket.

As of Phoenix at version greater or equal than 1.1.0, the framework allows for third party plug adapters to be fitted inside the application supervision tree. This project implements Phoenix.Endpoint.Handler behaviour for Pastelli.

See this in Action in a fork of the default phoenix chat example.

Instructions

Add :pastelli_phoenix to your phoenix app dependencies

Mix it in your Phoenix Application

def deps do
  [
    {:phoenix, "~> 1.4.0"},
    {:pastelli_phoenix, "~> 0.1.0", github: "zampino/pastelli_phoenix" },
    # ...
  ]
end

Configure your App

in config.exs or [env].exs

config :my_app, MyApp.Endpoint,
  handler: Pastelli.Phoenix,
  http: [
    port: {:system, "PORT"},
    # ...
  ]

like in here.

Plug Pastelli.Phoenix in your Endpoint

In your application endpoint use Pastelli.Phoenix.Endpoint module before the usual Phoenix.Endpoint.

A new plug module will be defined at compile time with the alias Pastelli.Phoenix.SocketDispatchRouter. This is to be plugged (anywhere you like but before MyApp.Router of course) and will convert phoenix sockets from cowboy-dispatch rules into Pastelli standard route dispatches. Pastelli will hand ws-upgrade connections over to elli_websocket.

Just like this:

defmodule MyApp.Endpoint do
  use Pastelli.Phoenix.Endpoint
  use Phoenix.Endpoint, otp_app: :chat

  plug Pastelli.Phoenix.SocketDispatchRouter

  socket "/socket", MyApp.UserSocket

  plug Plug.Static,
    at: "/", from: :my_app,
    only: ~w(css images js favicon.ico robots.txt)

  if code_reloading? do
    socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
    plug Phoenix.CodeReloader
    plug Phoenix.LiveReloader
  end

  # ... and the usual plug pipeline

  plug MyApp.Router
end

About

runs Phoenix framework over Elli server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages