145 lines
2.6 KiB
Markdown
145 lines
2.6 KiB
Markdown
# Nuxt 4 met Database
|
|
|
|
Een moderne Nuxt 4 applicatie met PostgreSQL database, draaiend via Docker Compose.
|
|
|
|
## Features
|
|
|
|
- 🚀 Nuxt 4 met TypeScript
|
|
- 🐘 PostgreSQL database
|
|
- 🐳 Docker & Docker Compose
|
|
- 🎨 Tailwind CSS voor styling
|
|
- 📊 Sequelize ORM voor database management
|
|
- 🔄 API routes voor CRUD operaties
|
|
|
|
## Quick Start
|
|
|
|
### 1. Clone en setup
|
|
```bash
|
|
git clone <repository-url>
|
|
cd nuxt-deploy
|
|
```
|
|
|
|
### 2. Start met Docker Compose
|
|
```bash
|
|
docker-compose up --build
|
|
```
|
|
|
|
### 3. Database migratie (eerste keer)
|
|
```bash
|
|
# In een nieuwe terminal
|
|
docker-compose exec nuxt-app npm run db:migrate
|
|
```
|
|
|
|
### 4. Open de applicatie
|
|
Ga naar [http://localhost:3000](http://localhost:3000)
|
|
|
|
## Development
|
|
|
|
### Lokale development (zonder Docker)
|
|
```bash
|
|
# Installeer dependencies
|
|
npm install
|
|
|
|
# Start PostgreSQL (via Docker)
|
|
docker-compose up postgres -d
|
|
|
|
# Setup database
|
|
npm run db:migrate
|
|
|
|
# Start development server
|
|
npm run dev
|
|
```
|
|
|
|
### Database management
|
|
```bash
|
|
# Run migrations
|
|
npm run db:migrate
|
|
|
|
# Create database
|
|
npm run db:create
|
|
|
|
# Seed database
|
|
npm run db:seed
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
### Users
|
|
- `GET /api/users` - Alle gebruikers ophalen
|
|
- `POST /api/users` - Nieuwe gebruiker aanmaken
|
|
|
|
### Posts
|
|
- `GET /api/posts` - Alle posts ophalen
|
|
- `POST /api/posts` - Nieuwe post aanmaken
|
|
|
|
## Database Schema
|
|
|
|
### User
|
|
- `id` (Int, Primary Key)
|
|
- `email` (String, Unique)
|
|
- `name` (String, Optional)
|
|
- `createdAt` (DateTime)
|
|
- `updatedAt` (DateTime)
|
|
|
|
### Post
|
|
- `id` (Int, Primary Key)
|
|
- `title` (String)
|
|
- `content` (String, Optional)
|
|
- `published` (Boolean, Default: false)
|
|
- `authorId` (Int, Foreign Key)
|
|
- `createdAt` (DateTime)
|
|
- `updatedAt` (DateTime)
|
|
|
|
## Docker Services
|
|
|
|
- **nuxt-app**: Nuxt 4 applicatie (poort 3000)
|
|
- **postgres**: PostgreSQL database (poort 5432)
|
|
|
|
## Environment Variables
|
|
|
|
Kopieer `env.example` naar `.env` en pas aan indien nodig:
|
|
|
|
```bash
|
|
cp env.example .env
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Database connection issues
|
|
```bash
|
|
# Check of PostgreSQL draait
|
|
docker-compose ps
|
|
|
|
# Check logs
|
|
docker-compose logs postgres
|
|
```
|
|
|
|
### Sequelize issues
|
|
```bash
|
|
# Run migrations
|
|
docker-compose exec nuxt-app npm run db:migrate
|
|
|
|
# Reset en herstart database
|
|
docker-compose down -v
|
|
docker-compose up --build
|
|
```
|
|
|
|
## Production Deployment
|
|
|
|
Voor productie deployment:
|
|
|
|
1. Update `docker-compose.yml` met productie instellingen
|
|
2. Gebruik environment variables voor secrets
|
|
3. Setup reverse proxy (nginx)
|
|
4. Configure SSL certificaten
|
|
5. Setup database backups
|
|
|
|
## Tech Stack
|
|
|
|
- **Frontend**: Nuxt 4, Vue 3, TypeScript
|
|
- **Backend**: Nuxt Server API
|
|
- **Database**: PostgreSQL 15
|
|
- **ORM**: Sequelize
|
|
- **Styling**: Tailwind CSS
|
|
- **Containerization**: Docker & Docker Compose
|