Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
# Binaries
trips-redirect

Expand Down
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
FROM golang:1.25-alpine AS builder
WORKDIR /app
# Install C build tools needed for CGO
RUN apk add --no-cache gcc musl-dev
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Build with CGO enabled
RUN CGO_ENABLED=1 go build -o redirector .
RUN go build -o redirector .

FROM alpine:3.18
RUN apk add --no-cache ca-certificates
Expand Down
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,38 @@ The service will automatically handle `www.` subdomains. For example, if you con

This will start the service on port 3000.

### Data Persistence
### Environment Variables

The visit statistics are stored in a SQLite database file. To ensure that your statistics are not lost when you update or restart the Docker container, you should store the database file on your host machine using a Docker volume.
The following environment variables can be configured:

You can specify the path for the database file inside the container by using the `DB_PATH` environment variable.
* `PORT` - The port to run the service on (default: 3000)

Here is an example of how to run the service with a persistent database stored in `/path/to/data/stats.db` on your host machine:
#### Rybbit Analytics (Optional)

The service supports [Rybbit Analytics](https://rybbit.io) for tracking redirections and errors. To enable analytics, set the following environment variables:

* `RYBBIT_API_KEY` - Your Rybbit API key
* `RYBBIT_API_URL` - The Rybbit API endpoint URL
* `RYBBIT_SITE_ID` - Your Rybbit site ID

All three variables must be set to enable analytics. If any variable is missing, analytics will be disabled.

**Example with analytics enabled:**

```bash
docker run -d \
-p 3000:3000 \
docker run -d -p 3000:3000 \
-v $(pwd)/domains.yaml:/domains.yaml \
-v /path/to/data:/data \
-e DB_PATH="/data/stats.db" \
--name trips-redirect \
trips-redirect
-e RYBBIT_API_KEY=your-api-key \
-e RYBBIT_API_URL=https://api.rybbit.io/events \
-e RYBBIT_SITE_ID=your-site-id \
--name trips-redirect trips-redirect
```

The service tracks the following events:
- **Pageview**: Successful redirections and profile fallbacks
- **Outbound**: Redirects to Polarsteps trip pages
- **Error**: 404 errors and API failures

## Contributing

Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request.
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ module trips-redirect
go 1.25.0

require gopkg.in/yaml.v3 v3.0.1

require github.com/mattn/go-sqlite3 v1.14.32 // indirect
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
Loading