1.5 KiB
1.5 KiB
Data Server
A Node.js server to handle file I/O operations for the ASSCO admin panel.
Setup
- Install dependencies:
cd data-server
npm install
- Copy environment variables:
cp .env.example .env
- Update the
.envfile with your settings:
ADMIN_PASSWORD: Same password used in your main appPORT: Port to run the server on (default: 3001)ALLOWED_ORIGINS: Comma-separated list of allowed origins for CORS
Running
Development
npm run dev
Production
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 codesPOST /api/discount-codes- Add new discount codeDELETE /api/discount-codes/:code- Delete discount code
Products
GET /api/products- Get all productsPUT /api/products/:productId- Update product price
Cache Management
GET /api/cache-status- View cache statusPOST /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