Enhanced Base API dengan fitur keamanan, performa, dan developer experience yang lebih baik.
- Rate Limiting: 100 requests per 15 menit dengan endpoint auth yang lebih ketat (5 requests per jam)
- Security Headers: Helmet integration dengan CSP, HSTS, dan security headers lainnya
- CORS: Konfigurasi CORS yang aman dengan origin validation
- Request ID Tracking: Setiap request memiliki unique identifier untuk tracing
- Response Compression: Gzip compression untuk response yang lebih kecil
- Caching: Node-cache untuk caching endpoint tertentu
- Structured Logging: Winston logger dengan JSON format di production
- Standardized API Response: Format response yang konsisten
- Input Validation: Express-validator untuk validasi input
- Health Checks:
/health,/ready, dan/metricsendpoints - Enhanced Frontend: UI yang lebih baik dengan search, keyboard shortcuts, dan animations
- Auto-generated API Info: Endpoint
/api/v1/infodengan semua endpoint yang tersedia - Interactive Documentation: Frontend dengan form untuk testing endpoint langsung
npm installBuat file .env berdasarkan .env.example:
cp .env.example .env# Development
npm run dev
# Production
npm startServer akan berjalan di http://localhost:3000
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/health |
Basic health check |
| GET | /api/v1/ready |
Readiness probe |
| GET | /api/v1/metrics |
System metrics |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/ai/gemini?text=&apikey= |
Chat with Gemini AI |
| GET | /api/v1/ai/gemini-with-system?text=&system=&apikey= |
Gemini dengan system instruction |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/downloader/videy?url= |
Download dari Videy |
| GET | /api/v1/downloader/threads?url= |
Download dari Threads |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/tools/ssweb-pc?url= |
Screenshot desktop |
| GET | /api/v1/tools/ssweb-hp?url= |
Screenshot mobile |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/info |
API information |
sawit-base-api/
βββ src/
β βββ config/ # Konfigurasi aplikasi
β βββ middleware/ # Express middleware
β β βββ errorHandler.js
β β βββ rateLimiter.js
β β βββ requestId.js
β β βββ security.js
β β βββ validation.js
β βββ routes/ # API routes
β β βββ api.js
β βββ services/ # Business logic
β β βββ healthService.js
β βββ utils/ # Utilities
β β βββ logger.js
β β βββ response.js
β βββ index.js # Entry point
βββ lib/ # Library files (scrapers, etc.)
βββ logs/ # Log files
βββ listapi.json # API documentation
βββ linkbio.json # Link bio configuration
βββ script.js # Frontend script
βββ package.json
| Variable | Default | Description |
|---|---|---|
PORT |
3000 | Port server |
NODE_ENV |
development | Environment (development/production) |
API_PREFIX |
/api/v1 | API prefix untuk versioning |
RATE_LIMIT_WINDOW_MS |
900000 | Rate limit window (15 menit) |
RATE_LIMIT_MAX_REQUESTS |
100 | Max requests per window |
CORS_ORIGIN |
* | CORS origin |
LOG_LEVEL |
info | Winston log level |
CACHE_TTL |
300 | Cache TTL dalam detik |
GEMINI_API_KEY |
- | Gemini API key |
/**
* GET /category/endpoint
* Deskripsi endpoint
*/
router.get('/category/endpoint', [
// Validasi jika diperlukan
query('param')
.notEmpty().withMessage('Parameter wajib diisi')
.isString(),
handleValidationErrors
], asyncHandler(async (req, res) => {
const { param } = req.query;
// Business logic
const result = await someFunction(param);
// Response
const response = successResponse({
data: result,
message: 'Success message',
statusCode: 200,
req
});
res.json(response);
}));{
"name": "CATEGORY NAME",
"items": [
{
"name": "ENDPOINT NAME",
"path": "/api/v1/category/endpoint?param=",
"desc": "Deskripsi endpoint",
"status": "ready",
"params": {
"param": "Deskripsi parameter"
}
}
]
}# Test health endpoint
curl http://localhost:3000/api/v1/health
# Test API info
curl http://localhost:3000/api/v1/info
# Test dengan validasi
curl "http://localhost:3000/api/v1/ai/gemini?text=hello&apikey=YOUR_KEY"- β Rate limiting otomatis
- β Helmet security headers
- β CORS dengan origin validation
- β Input validation
- β Request ID tracking
- β Structured logging
- β Error handling terpusat
Akses frontend di http://localhost:3000/ untuk:
- Melihat semua endpoint
- Testing langsung dari browser
- Melihat response format
- Fork repository ini
- Buat feature branch (
git checkout -b feature/amazing-feature) - Commit perubahan (
git commit -m 'Add amazing feature') - Push ke branch (
git push origin feature/amazing-feature) - Buat Pull Request
Project ini dilisensikan di bawah MIT License.
Dibuat dengan β€οΈ oleh SawitProject