Files
Tomas DvorakandDevin 060038cb6f feat: swap Redis for Dragonfly, fix remote installs, self-hosted email-only auth
- Replace redis:7-alpine with Dragonfly (Redis-protocol compatible; go-redis
  client unchanged) in root, infra, and backend-dev compose files. Bounded
  defaults --proactor_threads/--maxmemory so it boots on small VPSs.
- Frontend now defaults to same-origin API calls; nginx proxies /api/* to the
  backend (WebSocket-aware, docker DNS resolver for upstream re-resolution).
  Removes the baked localhost:8082 that broke installs reached by IP/domain.
- /auth/bootstrap returns configured OAuth providers; the UI hides
  GitHub/Google buttons unless real credentials exist. Self-hosted stays
  email/password only - OAuth reserved for a future managed offering.
- Sidecar ignores PLACEHOLDER_* OAuth credentials and trusts same-host
  origins dynamically (Origin host == request Host) so remote installs pass
  origin checks without config; cross-origin requests still rejected.
- install.sh writes ENVIRONMENT=production; COOKIE_SECURE=false in
  production is now a startup warning instead of fatal (plain-HTTP installs).
- Bootstrap failure surfaces an error notice instead of silently rendering
  the sign-in page.

Authored By: TDvorak <[email protected]>

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-21 17:24:43 +02:00

132 lines
3.0 KiB
Markdown

# Containr Backend Setup
## Quick Start
### Prerequisites
- Go 1.21+
- PostgreSQL 12+
- Dragonfly or Redis-compatible cache (optional)
### Environment Variables
Create a `.env` file or set these environment variables:
```bash
# Database
DATABASE_URL=postgres://containr:password@localhost:5432/containr?sslmode=disable
REDIS_URL=redis://localhost:6379
# Server
PORT=8080
ENVIRONMENT=development
# Security
JWT_SECRET=your-secret-key-change-in-production
# Frontend (for CORS)
FRONTEND_URL=http://localhost:3000
```
### Database Setup
1. Create PostgreSQL database:
```sql
CREATE DATABASE containr;
CREATE USER containr WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE containr TO containr;
```
2. Run migrations (handled automatically on server start)
### Running the Server
```bash
# Build
go build -o bin/server cmd/server/main.go
# Run
./bin/server
```
The server will start on `http://localhost:8080`
### API Endpoints
#### Health Check
- `GET /health` - Server health status
#### Authentication
- `POST /api/v1/auth/login` - User login
- `POST /api/v1/auth/register` - User registration
#### User Profile
- `GET /api/v1/user/profile` - Get user profile (requires auth)
- `PUT /api/v1/user/profile` - Update user profile (requires auth)
#### Projects
- `GET /api/v1/projects` - List user projects (requires auth)
- `POST /api/v1/projects` - Create project (requires auth)
- `GET /api/v1/projects/:id` - Get project details (requires auth)
- `PUT /api/v1/projects/:id` - Update project (requires auth)
- `DELETE /api/v1/projects/:id` - Delete project (requires auth)
### Authentication
Include JWT token in Authorization header:
```
Authorization: Bearer <your-jwt-token>
```
### Example Usage
1. Register a user:
```bash
curl -X POST http://localhost:8080/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "password123",
"name": "Test User"
}'
```
2. Login:
```bash
curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "password123"
}'
```
3. Create a project (using token from login):
```bash
curl -X POST http://localhost:8080/api/v1/projects \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"name": "My Project",
"description": "A test project"
}'
```
## Development
### Project Structure
```
cmd/server/ - Main application entry point
internal/
├── api/ - HTTP handlers and routes
├── config/ - Configuration management
├── database/ - Database connections and migrations
└── middleware/ - HTTP middleware
migrations_goose/ - Goose-managed migrations (single migration path)
```
### Adding New Endpoints
1. Create handler functions in `internal/api/`
2. Add routes in `internal/api/routes.go`
3. Update database schema if needed in `migrations_goose/` (goose format: `-- +goose Up/Down`)