feat: add flexible region matching to servers API

- Add shared buildFlexibleRegionConditions() in utils.ts
- Add COUNTRY_NAME_TO_REGIONS mapping for country/city expansion
- Update servers.ts to use flexible region matching (korea, tokyo, japan, etc.)
- Update recommend.ts to use shared function (remove duplicate code)
- Fix servers GROUP BY to show all regions (it.id, r.id)
- Update CLAUDE.md with single-line curl examples

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-01-25 19:36:34 +09:00
parent bfaa1d73e4
commit 67d86be5d5
4 changed files with 87 additions and 75 deletions

View File

@@ -90,9 +90,9 @@ Estimates monthly bandwidth based on use_case patterns:
Heavy bandwidth (>1TB/month) prefers Linode for included bandwidth.
### Flexible Region Matching (`candidates.ts`)
### Flexible Region Matching (`utils.ts`)
Region matching supports multiple input formats:
Both `/api/recommend` and `/api/servers` use shared `buildFlexibleRegionConditions()`:
```sql
LOWER(r.region_code) = ? OR
LOWER(r.region_code) LIKE ? OR
@@ -100,7 +100,9 @@ LOWER(r.region_name) LIKE ? OR
LOWER(r.country_code) = ?
```
Valid inputs: `"korea"`, `"KR"`, `"seoul"`, `"ap-northeast-2"`, `"icn"`
Valid inputs: `"korea"`, `"KR"`, `"seoul"`, `"tokyo"`, `"japan"`, `"ap-northeast-2"`, `"icn"`
Country names are auto-expanded via `COUNTRY_NAME_TO_REGIONS` mapping.
### AI Prompt Strategy (`recommend.ts`)
@@ -151,29 +153,23 @@ OPENAI_API_KEY = "sk-..." # Set via wrangler secret
## Testing
**Note**: Use single-line curl commands. Backslash line continuation (`\`) may not work in some environments.
```bash
# Health check
curl https://server-recommend.kappa-d8e.workers.dev/api/health
curl -s https://server-recommend.kappa-d8e.workers.dev/api/health | jq .
# Recommendation (e-commerce)
curl -X POST https://server-recommend.kappa-d8e.workers.dev/api/recommend \
-H "Content-Type: application/json" \
-d '{
"tech_stack": ["php", "mysql"],
"expected_users": 1000,
"use_case": "e-commerce shopping mall",
"region_preference": ["korea"]
}'
# Recommendation - nodejs/redis real-time chat (Japan)
curl -s -X POST https://server-recommend.kappa-d8e.workers.dev/api/recommend -H "Content-Type: application/json" -d '{"tech_stack":["nodejs","redis"],"expected_users":1000,"use_case":"real-time chat","region_preference":["japan"]}' | jq .
# Recommendation (analytics - heavier DB workload)
curl -X POST https://server-recommend.kappa-d8e.workers.dev/api/recommend \
-H "Content-Type: application/json" \
-d '{
"tech_stack": ["postgresql"],
"expected_users": 500,
"use_case": "analytics dashboard",
"region_preference": ["japan"]
}'
# Recommendation - php/mysql community forum (Korea)
curl -s -X POST https://server-recommend.kappa-d8e.workers.dev/api/recommend -H "Content-Type: application/json" -d '{"tech_stack":["php","mysql"],"expected_users":800,"use_case":"community forum","region_preference":["korea"]}' | jq .
# Recommendation - analytics dashboard (heavier DB workload)
curl -s -X POST https://server-recommend.kappa-d8e.workers.dev/api/recommend -H "Content-Type: application/json" -d '{"tech_stack":["postgresql"],"expected_users":500,"use_case":"analytics dashboard","region_preference":["japan"]}' | jq .
# Server list with filters (supports flexible region: korea, seoul, tokyo, etc.)
curl -s "https://server-recommend.kappa-d8e.workers.dev/api/servers?region=korea&minCpu=4" | jq .
```
## Recent Changes
@@ -201,5 +197,6 @@ curl -X POST https://server-recommend.kappa-d8e.workers.dev/api/recommend \
### Code Quality
- **Dead code removed**: Unused `queryVPSBenchmarks` function deleted
- **DRY**: `DEFAULT_REGION_FILTER_SQL` shared between handlers
- **DRY**: `DEFAULT_REGION_FILTER_SQL` and `buildFlexibleRegionConditions()` shared between handlers
- **Name-based filtering**: Provider queries use names, not hardcoded IDs
- **Flexible region matching**: Both endpoints support country/city/code inputs (korea, seoul, icn)