mirror of
https://github.com/FoggedLens/deflock.git
synced 2026-02-12 15:02:45 +00:00
DeFlock Backend Service
A Node.js TypeScript service providing API endpoints for the DeFlock application.
Features
- GitHub Sponsors: Fetch GitHub sponsors data
- Geocoding: Geocode addresses using Nominatim with LRU caching to avoid rate limits
Prerequisites
- Node.js 18+
- npm or yarn
Setup
- Install dependencies:
npm install
- Create a
.envfile based on.env.example:
cp .env.example .env
- Add your GitHub token to
.env:
GITHUB_TOKEN=your_github_token_here
PORT=8080
Development
Start the development server with hot reload:
npm run dev
Production
Build and start the production server:
npm run build
npm start
API Endpoints
Health Check
GET /api/healthcheck- Returns service health statusHEAD /api/healthcheck- Returns 200 OK
GitHub Sponsors
GET /api/sponsors/github- Fetches GitHub sponsors for the configured user
Geocoding
GET /api/geocode?query=<address>- Geocodes an address using Nominatim- Uses LRU cache (max 300 entries) to minimize API calls
- Respects Nominatim rate limits
Configuration
Environment Variables
GITHUB_TOKEN- GitHub personal access token with sponsorship read permissionsPORT- Server port (default: 8080)NODE_ENV- Environment mode (development/production)
CORS
Allowed origins are configured in server.ts:
Caching
The geocoding service uses an LRU cache with:
- Max 300 entries
- Automatic eviction of least recently used entries
- No TTL (cache persists until server restart)
Project Structure
backend/
├── src/
│ ├── server.ts # Main server file
│ └── services/
│ ├── github.ts # GitHub API client
│ └── nominatim.ts # Nominatim geocoding client with cache
├── package.json
├── tsconfig.json
└── .env.example