# Path Response Middleware for Traefik

## Local Development

### Prerequisites

Download traefik binary from the official website into the root of this project.

### Run

#### Traefik

```bash
./traefik
```
#### Whoami Service

```bash
docker run -d -P --name iamfoo traefik/whoami
```

Check the port of the `whoami` service:

```bash
docker inspect --format '{{ .NetworkSettings.Ports }}' iamfoo
```

Update `dynamic-discovery.yaml` with the port of the `whoami` service.

There is not specific reason why the `whoami` service is used. It is just a simple service that can be used to test the path response middleware.

#### Test

To test the path response middleware, you can use `curl`:

```bash
curl --header "uitest: true" "http://localhost:80/apollo-api/test/?request=1"
```

## Add new path

Create a new file under the mocks directory with the static response that you want to return.

Then add a new entry to the `[pathresponse.go](plugins-local%2Fsrc%2Fgithub.com%2Ftraefik%2Fplugin-pathresponse%2Fpathresponse.go)` file in the StaticConfig structure with the following format:

```go
{
    RequestUri: "/apollo-api/test/?request=1",
    FileName:   "mocks/test-1.json",
},
```

Where `RequestUri` is the path that you want to match with query arguments and `FileName` is the file that you want to return. The path to the file is relative to the traefik working directory.

## Troubleshooting 

If the changes didn't deploy trigger the build manually [here](https://jenkins.apollo.stream/job/Apollo/job/pipelines/job/traefik-plugin-pathresponse/job/master/)
