A simple Python API backend using Bottle framework with SQLite database and token-based authentication.
- Install dependencies:
pip install -r requirements.txt- Copy environment file:
cp env.example .env-
Customize the
.envfile with your settings (optional) -
Run the application:
python app.py- Copy environment file:
cp env.example .env-
Customize the
.envfile with your settings (optional) -
Build and run with Docker Compose:
docker-compose up --build- Build production image:
docker build -f Dockerfile.prod -t reactor-backend:prod .- Run production container:
docker run -d \
--name reactor-backend \
-p 8080:8080 \
-e DEFAULT_ADMIN_PASSWORD=your_secure_password \
-v $(pwd)/data:/app/data \
reactor-backend:prodThe server will start on http://localhost:8080 and automatically create the database with a default admin user.
Copy env.example to .env and customize the following variables:
DB_PATH: Database file path (default:users.db)DB_TYPE: Database type (default:sqlite)
HOST: Server host (default:localhostfor local,0.0.0.0for Docker)PORT: Server port (default:8080)DEBUG: Enable debug mode (default:true)RELOADER: Enable auto-reload (default:true)
DEFAULT_ADMIN_USERNAME: Default admin username (default:admin)DEFAULT_ADMIN_PASSWORD: Default admin password (default:admin123)SESSION_EXPIRY_HOURS: Session expiration time in hours (default:24)
TOKEN_LENGTH: Length of session tokens (default:32)
- Username:
admin(configurable viaDEFAULT_ADMIN_USERNAME) - Password:
admin123(configurable viaDEFAULT_ADMIN_PASSWORD)
Login with username and password.
Request Body:
{
"username": "admin",
"password": "admin123"
}Response:
{
"token": "your_session_token",
"expires_at": "2024-01-01T12:00:00",
"message": "Login successful"
}Logout and invalidate the current session token.
Headers:
Authorization: Bearer your_session_token
Response:
{
"message": "Logout successful"
}Get the current user's profile information.
Headers:
Authorization: Bearer your_session_token
Response:
{
"username": "admin",
"created_at": "2024-01-01T10:00:00"
}Check if the API is running.
Response:
{
"status": "ok",
"message": "API is running"
}id: Primary keyusername: Unique usernamepassword_hash: SHA256 hash of passwordcreated_at: User creation timestamp
id: Primary keyuser_id: Foreign key to users tabletoken: Unique session tokencreated_at: Session creation timestampexpires_at: Session expiration timestamp
# Login
curl -X POST http://localhost:8080/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "admin123"}'
# Get profile (replace YOUR_TOKEN with the token from login response)
curl -X GET http://localhost:8080/profile \
-H "Authorization: Bearer YOUR_TOKEN"
# Logout
curl -X POST http://localhost:8080/logout \
-H "Authorization: Bearer YOUR_TOKEN"
# Health check
curl -X GET http://localhost:8080/healthCopy database from docker image to root:
docker cp reactor-backend:/app/users.db ./users.db