|
||
---|---|---|
.bolt | ||
.gitea/workflows | ||
helm/logingest | ||
middleware | ||
services | ||
supabase/migrations | ||
utils | ||
.env.example | ||
.gitignore | ||
Dockerfile | ||
README.md | ||
index.js | ||
package-lock.json | ||
package.json | ||
server.js |
README.md
Log Microservice
A Node.js microservice that receives log data via POST requests with basic authentication and stores them in a PostgreSQL database via Supabase.
Features
- HTTP API: RESTful endpoints for receiving log data
- Basic Authentication: Secure endpoints with username/password authentication
- PostgreSQL Storage: Stores logs in Supabase PostgreSQL database
- Input Validation: Validates incoming data and provides meaningful error messages
- Default Values: Automatically applies default values for optional fields
- Health Check: Built-in health check endpoint
API Endpoints
POST /logs
Receives log data and stores it in the database.
Authentication: Basic Auth required
Request Body:
{
"message": "This is a log message (required)",
"project": "My Project (optional, defaults to 'Project 1')",
"type": "Error (optional, defaults to 'Info')",
"owner": "john.doe (optional, defaults to 'N/A')",
"avatar_src": "/custom-avatar.png (optional, defaults to '/rectangle-15.png')",
"status": "Active (optional, defaults to 'Pending')"
}
Response:
{
"success": true,
"message": "Log entry created successfully",
"id": 1703123456
}
GET /health
Health check endpoint to verify service status.
Response:
{
"status": "healthy",
"timestamp": "2024-01-01T12:00:00.000Z"
}
Setup
- Set up Supabase: Click the "Connect to Supabase" button to configure your database
- Configure Environment: Copy
.env.example
to.env
and update the values - Run the Service: Use
npm start
to start the microservice
Database Schema
The service automatically creates a logs
table with the following structure:
id
(bigint) - Epoch time identifierbody
(text) - First 200 characters of the messageproject
(text) - Project nametype
(text) - Log type (Info, Error, Warning, etc.)date
(date) - Date of the log entryavatar_src
(text) - Avatar image sourceowner
(text) - Owner of the log entrydescription
(text) - Full log messagecreated_at
(timestamptz) - Creation timestampstatus
(text) - Status of the log entry
Authentication
The service uses HTTP Basic Authentication. Default credentials:
- Username:
admin
- Password:
password123
Update these in your .env
file for production use.
Usage Example
# Using curl to send a log entry
curl -X POST http://localhost:3000/logs \
-H "Content-Type: application/json" \
-H "Authorization: Basic YWRtaW46cGFzc3dvcmQxMjM=" \
-d '{
"message": "User login successful",
"project": "Authentication Service",
"type": "Info",
"owner": "auth-service"
}'
Error Handling
The service provides detailed error responses:
400 Bad Request
: Invalid input data401 Unauthorized
: Missing or invalid authentication404 Not Found
: Unknown endpoint500 Internal Server Error
: Database or server errors