Skip to content

Latest commit

 

History

History
 
 

server

GitHub tag Build Status License Join our slack

Svix is the enterprise ready webhook service

Svix makes it easy for developers to send webhooks. Developers make one API call, and Svix takes care of deliverability, retries, security, and more. For more information, please refer to the Svix homepage.

Running the server

For information on how to use this server please refer to the running the server in the main README.

Building from source

You would need a working Rust complier in order to build Svix server. The easiest way is to use rustup.

# Clone the repository
git clone https://github.com/svix/svix-webhooks
# Change to the source directory
cd svix-webhooks/server/
# Build
cargo install --path svix-server

Development

Setup your environment

Make sure you have a working Rust compiled (e.g. by using rustup).

Once rustup is installed make sure to set up the stable toolchain by running:

$ rustup default stable

Afterwards please install the following components:

$ rustup component add clippy rust-src cargo rustfmt

Install SQLx CLI for database migrations

$ cargo install sqlx-cli

For automatic reload while developing:

$ cargo install cargo-watch

Run the development server

To run the auto-reloading development server run:

# Move to the inner svix-server directory.
cd svix-server
cargo watch -x run

This however will fail, as you also need to point the server to the database and setup a few other configurations.

The easiest way to achieve that is to use docker-compose to setup a dockerize development environment, and the related config.

# From the svix inner directory
cp development.env .env
# Set up docker (may need sudo depending on your setup)
docker-compose up

Now run cargo watch -x run again to start the development server against your local docker environment.

Now generate an auth token, you can do it by running:

cargo run jwt generate

Run the SQL migrations

One last missing piece to the puzzle is running the SQL migrations.

From the same directory as the .env file run:

cargo sqlx migrate run

More useful commands:

# View the migrations and their status
cargo sqlx migrate info
# Reverting the latest migration
cargo sqlx migrate revert

Creating new SQL migration

As you saw before you run/revert migrations. To generate new migrations you just run:

cargo sqlx migrate add -r MIGRATION_NAME

And fill up the created migration files.

Linting

Please run these two commands before pushing code:

cargo clippy --fix
cargo fmt

Testing

When run with the integration_testing feature, cargo test will run tests that assume a running PostgreSQL and Redis database. These databases are configured with the same environment variables as with running the actual server.

The easiest way to get these tests to pass is to: 1. Use the testing-docker-compose.yml file with docker-compose to launch the databases on their default ports. 2. Create a .env file as you would when running the server for real. 3. Migrate the database with cargo run -- migrate. 4. Run cargo test --all-targets

Without this feature enabled, these tests will show as ignored when running cargo test and only pure functions may be tested.