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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.14'
cache: pip
- run: python -m pip install -r requirements.txt
- run: python -m unittest discover -s tests -v
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.14
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:3.14-slim
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
Expand Down
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# MCStatus API

Minecraft Java 서버의 접속 가능 여부와 상태를 조회하는 API입니다. Python 3.10을 사용하며, Redis 또는 인메모리 캐시를 선택할 수 있습니다.
An API for checking Minecraft Java server availability and status. Runs on Python 3.14 with a choice of Redis or in-memory caching.

## 실행·배포
## Run and deploy

Docker와 Docker Compose가 필요합니다. 저장소 루트에서 실행합니다.
Requires Docker and Docker Compose. Run these commands from the repository root:

```bash
docker build -t ksi12345ab/mcstatus-api .
docker compose up -d
```

API는 `8000` 포트에서 실행됩니다. 코드 변경 후에는 이미지를 다시 빌드하고 같은 명령으로 컨테이너를 갱신합니다.
The API listens on port `8000`. After changing the code, rebuild the image and run the same commands to update the container.

| 환경 변수 | 기본값 | 설명 |
| Environment variable | Default | Description |
| --- | --- | --- |
| `CACHE_BACKEND` | `redis` | `redis` 또는 `memory`. 다른 값이면 시작 실패 |
| `REDIS_URL` | `redis://localhost` | Redis 선택 시 연결 주소. Compose에서는 `redis://redis:6379` |
| `CACHE_BACKEND` | `redis` | `redis` or `memory`. Other values prevent startup. |
| `REDIS_URL` | `redis://localhost` | Connection URL when using Redis. Compose sets this to `redis://redis:6379`. |

Redis 없이 인메모리 캐시로 API만 실행하려면 다음 명령을 사용합니다.
To run only the API with in-memory caching and no Redis:

```bash
CACHE_BACKEND=memory docker compose up -d mcstatus-api
```

인메모리 캐시는 프로세스별로 독립적이며 재시작하면 초기화됩니다. 최대 10,000개를 보관하고, 저장 시 만료 항목과 가장 오래 사용하지 않은 항목을 정리합니다.
The in-memory cache is isolated per process and cleared on restart. It holds up to 10,000 entries. Writes remove expired entries and evict the least recently used entries when needed.

```bash
# Check status and logs
Expand All @@ -37,28 +37,28 @@ docker compose down

## API

- 운영 주소: `https://mcstatus.snowfrost.kr`
- 상태 조회: `GET /java/{address}` (예: `/java/example.com:25565`)
- 포트 생략 시 SRV 레코드를 조회하고, 레코드가 없으면 `25565`를 사용합니다.
- API 문서: 실행 중인 서버의 `/docs` 또는 `/openapi.json`
- Production URL: `https://mcstatus.snowfrost.kr`
- Server status: `GET /java/{address}` (for example, `/java/example.com:25565`)
- If the port is omitted, an SRV lookup is performed, falling back to port `25565` when no record is found.
- API documentation: `/docs` or `/openapi.json` on the running server.

| HTTP | 의미 |
| HTTP | Meaning |
| --- | --- |
| 200, `result: true` | 접속 가능. `status`에 서버 상태 포함 |
| 200, `result: false` | 접속 불가. `status: null`, `error`에 진단 메시지 포함 |
| 400 | 잘못된 대상 주소 |
| 502 | DNS 환경 또는 서버 응답 오류 |
| 500 | API 내부 오류 |

`status.latency`는 API 서버에서 Minecraft 서버까지의 status 응답 시간(ms)이며, 측정값이 없으면 `null`입니다. `timestamp`는 조회 완료 시각(UTC)입니다. HTTP 오류를 Minecraft 서버의 오프라인 상태로 판단하지 마세요.

## 조회·캐시 동작

- DNS 조회와 status 요청을 합쳐 3초로 제한합니다.
- 접속 가능·불가 결과를 선택한 백엔드에 60초 캐싱합니다. 캐시 응답은 기존 측정값과 시각을 유지합니다.
- 같은 프로세스에서 같은 주소의 동시 요청은 하나의 조회 결과를 공유하며, 신규 조회를 공유한 응답은 모두 `MISS`로 표시합니다. 다른 주소는 병렬 조회하며, 워커·컨테이너 간 중복 조회는 막지 않습니다.
- 4xx/5xx 오류는 캐싱하지 않습니다.
- `X-Cache: HIT/MISS/BYPASS`로 캐시 재사용·신규 저장·우회를 구분합니다.
- `X-Cache-Created-At`은 캐시 저장 시각(UTC)이며 HIT에서도 유지됩니다. 저장하지 않은 응답에는 포함하지 않습니다.
- 요청의 캐시 지시어와 조건부 요청 헤더는 무시하며, 항상 서버의 60초 TTL을 따릅니다.
- Redis 읽기·쓰기 실패는 로그에 기록하며, 캐시 없이 실제 조회 결과를 반환합니다.
| 200, `result: true` | Server reachable. `status` contains the server details. |
| 200, `result: false` | Server unreachable. `status` is `null`; `error` contains a diagnostic message. |
| 400 | Invalid target address. |
| 502 | DNS infrastructure or upstream server response error. |
| 500 | Internal API error. |

`status.latency` is the status response time from the API server to the Minecraft server in milliseconds, or `null` if unavailable. `timestamp` is the query completion time in UTC. Do not interpret HTTP errors as a Minecraft server being offline.

## Queries and caching

- DNS lookup and the status request have a combined timeout of 3 seconds.
- Both reachable and unreachable results are cached for 60 seconds in the selected backend. Cached responses retain the original measurements and timestamp.
- Concurrent requests for the same address within one process share a single lookup. Responses sharing a new lookup all report `MISS`. Different addresses are queried in parallel. Requests are not coalesced across workers or containers.
- HTTP 4xx/5xx errors are not cached.
- `X-Cache: HIT/MISS/BYPASS` indicates a cached response, a newly stored result, or a cache bypass.
- `X-Cache-Created-At` is the cache creation time in UTC, preserved on hits. It is omitted when the result is not stored.
- Request cache directives and conditional request headers are ignored. The server always uses its 60-second TTL.
- Redis read/write failures are logged. The API returns the actual query result without caching.
Loading
Loading