Pushy is a simple server to send SSE (Server-Sent Events) to HTTP clients. It allows you to listen to a list of channels and post events to them.
- Elixir ~> 1.12
- Erlang/OTP 23+
-
Clone the repository:
git clone https://github.com/ananto30/pushy.git cd pushy
-
Install dependencies:
mix deps.get
-
Compile the project:
mix compile
To start the server, set environment variables for the AUTH_SECRET_KEY
export AUTH_SECRET_KEY=secret
then run:
mix run --no-halt
The server will start on port 4000 by default.
Very first thing you need to do is to generate a token to authenticate the client. You can generate a token by running:
mix run -e "{:ok, token} = Pushy.Auth.make_token(%{user_id: 1}); IO.puts(\"Generated JWT Token: #{token}\")"
To listen to channels, make an HTTP POST request to /sse
with the channel names in the body.
Example using script:
elixir example/listen.exs
** Update the token in the file before running the script.
To post an event to a channel, make an HTTP POST request to /publish/:channel_name
with the event data in the request body.
Example using script:
elixir example/publish.exs
** Update the token in the file before running the script.
To run the tests, execute:
mix test
To build the Docker image for your Elixir application, run the following command in the root directory of your project:
docker build -t pushy:latest . --build-arg AUTH_SECRET_KEY=secret
*Creating AUTH_SECRET_KEY
as a build argument will reduce runtime signed token validation execution time.
To run the Docker container, execute:
docker run -p 4000:4000 pushy:latest
The server will start on port 4000 inside the container and will be exposed on port 4000 on your host machine.
Pushy uses the following dependencies:
plug_cowboy
- A Plug adapter for Cowboyjason
- A JSON library for Elixiruuid
- A UUID library for Elixirphoenix_pubsub
- A distributed PubSub system for Phoenixjoken
- A JSON Web Token (JWT) library for Elixir
This project is licensed under the MIT License.