https://github.com/ananto30/pushy
Open-source Pusher alternative
https://github.com/ananto30/pushy
elixir pusher server-sent-events sse
Last synced: 8 months ago
JSON representation
Open-source Pusher alternative
- Host: GitHub
- URL: https://github.com/ananto30/pushy
- Owner: Ananto30
- Created: 2023-01-01T20:22:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-06T10:17:24.000Z (about 1 year ago)
- Last Synced: 2025-05-06T11:31:10.839Z (about 1 year ago)
- Topics: elixir, pusher, server-sent-events, sse
- Language: Elixir
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pushy
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.
## ๐ Requirements
* Elixir ~> 1.12
* Erlang/OTP 23+
## ๐ Installation
1. Clone the repository:
```sh
git clone https://github.com/ananto30/pushy.git
cd pushy
```
2. Install dependencies:
```sh
mix deps.get
```
3. Compile the project:
```sh
mix compile
```
## ๐โโ๏ธ Running the Server
To start the server, set environment variables for the `AUTH_SECRET_KEY`
```sh
export AUTH_SECRET_KEY=secret
```
then run:
```sh
mix run --no-halt
```
The server will start on port 4000 by default.
## ๐ Usage
### Auth Token
Very first thing you need to do is to generate a token to authenticate the client. You can generate a token by running:
```sh
mix run -e "{:ok, token} = Pushy.Auth.make_token(%{user_id: 1}); IO.puts(\"Generated JWT Token: #{token}\")"
```
### Listening to Channels
To listen to channels, make an HTTP POST request to `/sse` with the channel names in the body.
Example using [script](/example/listen.exs):
```sh
elixir example/listen.exs
```
\*\* Update the token in the file before running the script.
### Posting Events to Channels
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](/example/publish.exs):
```sh
elixir example/publish.exs
```
\*\* Update the token in the file before running the script.
## ๐งช Testing
To run the tests, execute:
```sh
mix test
```
## ๐ณ Docker Instructions
### Building the Docker Image
To build the Docker image for your Elixir application, run the following command in the root directory of your project:
```sh
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.*
### Running the Docker Container
To run the Docker container, execute:
```sh
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.
## ๐ฆ Dependencies
Pushy uses the following dependencies:
* `plug_cowboy` - A Plug adapter for Cowboy
* `jason` - A JSON library for Elixir
* `uuid` - A UUID library for Elixir
* `phoenix_pubsub` - A distributed PubSub system for Phoenix
* `joken` - A JSON Web Token (JWT) library for Elixir
## ๐ License
This project is licensed under the MIT License.