assco-backend/README.md
2025-09-28 18:33:16 +01:00

73 lines
1.5 KiB
Markdown

# Data Server
A Node.js server to handle file I/O operations for the ASSCO admin panel.
## Setup
1. Install dependencies:
```bash
cd data-server
npm install
```
2. Copy environment variables:
```bash
cp .env.example .env
```
3. Update the `.env` file with your settings:
- `ADMIN_PASSWORD`: Same password used in your main app
- `PORT`: Port to run the server on (default: 3001)
- `ALLOWED_ORIGINS`: Comma-separated list of allowed origins for CORS
## Running
### Development
```bash
npm run dev
```
### Production
```bash
npm start
```
## API Endpoints
All endpoints except `/health` and GET requests require authentication via `Authorization: Bearer <admin_password>` header.
### Health Check
- `GET /health` - Server health status
### Discount Codes
- `GET /api/discount-codes` - Get all discount codes
- `POST /api/discount-codes` - Add new discount code
- `DELETE /api/discount-codes/:code` - Delete discount code
### Products
- `GET /api/products` - Get all products
- `PUT /api/products/:productId` - Update product price
### Cache Management
- `GET /api/cache-status` - View cache status
- `POST /api/clear-cache` - Clear all cache (requires auth)
## Caching
The server implements in-memory caching:
- GET requests serve from cache if available
- Non-GET requests clear the cache to ensure fresh data
- Cache includes timestamps for debugging
## File Structure
```
data-server/
├── data/
│ ├── discountCodes.json
│ └── products.js
├── server.js
├── package.json
├── .env.example
└── README.md
```