This project includes a webhook handler for the hxckr platform built with Node.js and Express, along with a RabbitMQ development environment set up using a Nix flake.
- Receives webhook payloads via HTTP POST requests
- Logs the entire payload for each received webhook
- Handles 'push' events specifically, with extensibility for other event types
- Returns a JSON response confirming receipt of the webhook
This repo uses a Nix flake to set up a RabbitMQ development environment. It provides an isolated environment with RabbitMQ server and necessary tools.
- Nix package manager with flakes enabled (download)
-
Clone this repository:
git clone <repository-url> cd <repository-directory>
-
Enter the Nix development shell:
nix develop
This command will download and set up all necessary dependencies, including RabbitMQ server.
-
Once in the Nix shell, you'll see output similar to:
RabbitMQ development environment Run 'rabbitmq-server' to start RabbitMQ RabbitMQ Connection String: amqp://guest:guest@localhost:5672 RabbitMQ data directory: /tmp/rabbitmq-<username> Available commands: rabbitmq-server - Start the RabbitMQ server rabbitmqctl - RabbitMQ management tool rabbitmq-plugins - RabbitMQ plugin management tool
To start the RabbitMQ server, run:
rabbitmq-server
This will start RabbitMQ in the foreground. To stop it, press Ctrl+C.
Use the connection string provided in the shell output to connect to RabbitMQ from your applications. The default connection string is:
amqp://guest:guest@localhost:5672
- Username: guest
- Password: guest
- Host: localhost
- Port: 5672
- Use
rabbitmqctl
for management tasks (e.g.,rabbitmqctl list_queues
) - Use
rabbitmq-plugins
to manage plugins (e.g.,rabbitmq-plugins enable rabbitmq_management
)
RabbitMQ data is stored in a temporary directory (shown in the shell output). This data will be lost when you reboot your system. For persistent data, modify the flake.nix
to use a permanent directory.
To exit the Nix development shell, simply type exit
or press Ctrl+D.
To customize the RabbitMQ configuration or change default settings, modify the flake.nix
file in this repository.
- Node.js and Yarn
- TypeScript
-
Install the dependencies:
yarn install
-
Create a
.env
file:cp .env.example .env
Fill in the necessary values.
For development:
yarn dev
This will start the server in watch mode and restart on file changes.
The webhook handler exposes a single endpoint:
- POST
/webhook
To test with the git-service:
- Set up git-service using hxckr-infra.
- Ensure the server is running.
- Create, clone, and push to a repo on soft-serve.
- Fork this repository.
- Create a branch:
git checkout -b <branch_name>
. - Make your changes and commit them:
git commit -m '<commit_message>'
- Push to the original branch:
git push origin <project_name>/<location>
- Create the pull request.
-
Build the Docker image:
docker build -t webhook-handler .
-
Run the container:
docker run -p 3000:3000 -e NODE_ENV=development -v $(pwd)/src:/app/src -d webhook-handler
-
View logs:
docker logs -f <container_id>
-
Stop the container:
docker stop <container_id>
Note: For hot-reloading in development, you may need to adjust the Dockerfile and use a tool like nodemon.