chore: default to port 8000
This commit is contained in:
@@ -74,11 +74,11 @@ COPY --from=builder /usr/local/bin/pokedex-api /usr/local/bin/pokedex-api
|
||||
|
||||
ARG GIT_SHA=unknown
|
||||
ENV GIT_SHA=$GIT_SHA \
|
||||
BIND_ADDR=0.0.0.0:5000
|
||||
BIND_ADDR=0.0.0.0:8000
|
||||
|
||||
EXPOSE 5000
|
||||
EXPOSE 8000
|
||||
USER app
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD curl -fsS http://127.0.0.1:5000/health || exit 1
|
||||
CMD curl -fsS http://127.0.0.1:8000/health || exit 1
|
||||
|
||||
CMD ["pokedex-api"]
|
||||
|
||||
6
Makefile
6
Makefile
@@ -4,7 +4,7 @@ CARGO ?= cargo
|
||||
DOCKER ?= docker
|
||||
IMAGE ?= pokedex-api
|
||||
TAG ?= local
|
||||
BASE_URL ?= http://localhost:5000
|
||||
BASE_URL ?= http://localhost:8000
|
||||
POKEMON ?= mewtwo
|
||||
PLATFORMS ?= linux/amd64,linux/arm64
|
||||
GIT_SHA ?= $(shell git rev-parse HEAD 2>/dev/null || printf unknown)
|
||||
@@ -15,7 +15,7 @@ help:
|
||||
@printf 'Available targets:\n'
|
||||
@printf ' make run Run the API locally with cargo\n'
|
||||
@printf ' make docker-build Build the Docker image\n'
|
||||
@printf ' make docker-run Run the Docker image on port 5000\n'
|
||||
@printf ' make docker-run Run the Docker image on port 8000\n'
|
||||
@printf ' make cli-health Call /health through the CLI helper\n'
|
||||
@printf ' make cli-pokemon Call /pokemon/$${POKEMON} through the CLI helper\n'
|
||||
@printf ' make cli-translated Call /pokemon/translated/$${POKEMON} through the CLI helper\n'
|
||||
@@ -34,7 +34,7 @@ docker-build:
|
||||
$(DOCKER) build -t $(IMAGE) .
|
||||
|
||||
docker-run:
|
||||
$(DOCKER) run --rm -p 5000:5000 $(IMAGE)
|
||||
$(DOCKER) run --rm -p 8000:8000 $(IMAGE)
|
||||
|
||||
cli-health:
|
||||
$(CARGO) run --bin pokedex-cli -- health
|
||||
|
||||
@@ -37,7 +37,7 @@ Then run the service:
|
||||
make run
|
||||
```
|
||||
|
||||
The API listens on `0.0.0.0:5000` by default.
|
||||
The API listens on `0.0.0.0:8000` by default.
|
||||
|
||||
## CLI helper
|
||||
|
||||
@@ -47,7 +47,7 @@ With the API running in another terminal, call it through the small helper binar
|
||||
make cli-health
|
||||
make cli-pokemon
|
||||
make cli-translated
|
||||
make cli-pokemon POKEMON=pikachu BASE_URL=http://localhost:5000
|
||||
make cli-pokemon POKEMON=pikachu BASE_URL=http://localhost:8000
|
||||
```
|
||||
|
||||
## Endpoints
|
||||
@@ -110,7 +110,7 @@ External contract tests are separated from the normal deterministic test suite.
|
||||
|
||||
| Variable | Default | Description |
|
||||
| --------------------------- | ------------------------------------------- | -------------------------- |
|
||||
| `BIND_ADDR` | `0.0.0.0:5000` | HTTP bind address |
|
||||
| `BIND_ADDR` | `0.0.0.0:8000` | HTTP bind address |
|
||||
| `POKEAPI_BASE_URL` | `https://pokeapi.co/api/v2` | PokéAPI base URL |
|
||||
| `FUN_TRANSLATIONS_BASE_URL` | `https://api.funtranslations.mercxry.me/v1` | FunTranslations base URL |
|
||||
| `REQUEST_TIMEOUT_SECONDS` | `5` | Upstream HTTP timeout |
|
||||
|
||||
@@ -4,7 +4,7 @@ info:
|
||||
version: 0.1.0
|
||||
description: REST API for the TrueLayer Pokémon challenge.
|
||||
servers:
|
||||
- url: http://localhost:5000
|
||||
- url: http://localhost:8000
|
||||
paths:
|
||||
/health:
|
||||
get:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
use std::{env, process::ExitCode, time::Duration};
|
||||
|
||||
const DEFAULT_BASE_URL: &str = "http://localhost:5000";
|
||||
const DEFAULT_BASE_URL: &str = "http://localhost:8000";
|
||||
const REQUEST_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
#[tokio::main]
|
||||
@@ -166,7 +166,7 @@ fn trim_base_url(base_url: &str) -> String {
|
||||
}
|
||||
|
||||
const fn usage() -> &'static str {
|
||||
"Usage:\n pokedex-cli [--base-url URL] health\n pokedex-cli [--base-url URL] metrics\n pokedex-cli [--base-url URL] pokemon <name>\n pokedex-cli [--base-url URL] translated <name>\n\nExamples:\n pokedex-cli pokemon mewtwo\n pokedex-cli translated mewtwo\n pokedex-cli --base-url http://localhost:5000 pokemon pikachu"
|
||||
"Usage:\n pokedex-cli [--base-url URL] health\n pokedex-cli [--base-url URL] metrics\n pokedex-cli [--base-url URL] pokemon <name>\n pokedex-cli [--base-url URL] translated <name>\n\nExamples:\n pokedex-cli pokemon mewtwo\n pokedex-cli translated mewtwo\n pokedex-cli --base-url http://localhost:8000 pokemon pikachu"
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
@@ -204,23 +204,23 @@ mod tests {
|
||||
}
|
||||
}
|
||||
);
|
||||
assert_eq!(args.url(), "http://localhost:5000/pokemon/mewtwo");
|
||||
assert_eq!(args.url(), "http://localhost:8000/pokemon/mewtwo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_custom_base_url_and_translated_command() {
|
||||
let args = parse_args([
|
||||
"--base-url",
|
||||
"http://localhost:5000/",
|
||||
"http://localhost:8000/",
|
||||
"translated",
|
||||
"mr-mime",
|
||||
])
|
||||
.expect("args should parse");
|
||||
|
||||
assert_eq!(args.base_url, "http://localhost:5000");
|
||||
assert_eq!(args.base_url, "http://localhost:8000");
|
||||
assert_eq!(
|
||||
args.url(),
|
||||
"http://localhost:5000/pokemon/translated/mr-mime"
|
||||
"http://localhost:8000/pokemon/translated/mr-mime"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ fn env_or_string(name: &'static str, default: &str) -> String {
|
||||
}
|
||||
|
||||
fn default_bind_addr() -> SocketAddr {
|
||||
SocketAddr::from(([0, 0, 0, 0], 5000))
|
||||
SocketAddr::from(([0, 0, 0, 0], 8000))
|
||||
}
|
||||
|
||||
const fn validate_rate_limit(per_second: f64, burst: u32) -> Result<(), ConfigError> {
|
||||
@@ -101,7 +101,7 @@ mod tests {
|
||||
fn default_config_is_valid_for_local_development() {
|
||||
let config = AppConfig::default_local();
|
||||
|
||||
assert_eq!(config.bind_addr.port(), 5000);
|
||||
assert_eq!(config.bind_addr.port(), 8000);
|
||||
assert_eq!(config.pokeapi_base_url, "https://pokeapi.co/api/v2");
|
||||
assert!((config.rate_limit_per_second - 20.0).abs() < f64::EPSILON);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user