167 lines
3.9 KiB
Markdown
167 lines
3.9 KiB
Markdown
# ConfigVault — Kurulum Rehberi
|
||
|
||
## 1. PostgreSQL — Database kurulumu
|
||
|
||
Herhangi bir Postgres çalışır: kendi sunucun, Railway, Render, Neon, Fly.io...
|
||
|
||
```bash
|
||
# Lokal kurulum için (macOS):
|
||
brew install postgresql && brew services start postgresql
|
||
createdb configvault
|
||
|
||
# Veya Docker ile:
|
||
docker run -d --name configvault-db \
|
||
-e POSTGRES_DB=configvault \
|
||
-e POSTGRES_PASSWORD=password \
|
||
-p 5432:5432 postgres:16
|
||
```
|
||
|
||
Schema'yı yükle:
|
||
|
||
```bash
|
||
psql postgresql://postgres:password@localhost:5432/configvault < schema.sql
|
||
```
|
||
|
||
Veya `psql`'e bağlanıp `schema.sql` içeriğini yapıştır.
|
||
|
||
---
|
||
|
||
## 2. Proje kurulumu
|
||
|
||
```bash
|
||
npm install
|
||
cp .env.example .env.local
|
||
```
|
||
|
||
`.env.local` doldur:
|
||
|
||
```bash
|
||
DATABASE_URL=postgresql://postgres:password@localhost:5432/configvault
|
||
DATABASE_SSL=false
|
||
|
||
NEXTAUTH_SECRET=$(openssl rand -base64 32)
|
||
NEXTAUTH_URL=http://localhost:3000
|
||
|
||
ADMIN_USERNAME=admin
|
||
# Şifre hash'i oluştur:
|
||
node -e "const b=require('bcryptjs'); console.log(b.hashSync('şifren', 12))"
|
||
ADMIN_PASSWORD_HASH=$2a$12$...
|
||
|
||
NEXT_PUBLIC_APP_URL=http://localhost:3000
|
||
```
|
||
|
||
## 3. Çalıştır
|
||
|
||
```bash
|
||
npm run dev
|
||
# → http://localhost:3000
|
||
```
|
||
|
||
---
|
||
|
||
## Deploy seçenekleri
|
||
|
||
### Vercel + Railway (kolay)
|
||
1. Railway'de PostgreSQL aç → connection string'i al
|
||
2. Vercel'e deploy et, env variable'ları ekle
|
||
3. `DATABASE_SSL=true` yap (Railway SSL ister)
|
||
|
||
### Kendi sunucun (VPS)
|
||
```bash
|
||
# Sunucuda:
|
||
npm run build
|
||
npm start
|
||
# Veya PM2 ile:
|
||
pm2 start npm --name configvault -- start
|
||
```
|
||
|
||
### Docker Compose (her şey bir arada)
|
||
```yaml
|
||
version: '3.8'
|
||
services:
|
||
app:
|
||
build: .
|
||
ports: ["3000:3000"]
|
||
environment:
|
||
DATABASE_URL: postgresql://postgres:password@db:5432/configvault
|
||
DATABASE_SSL: "false"
|
||
NEXTAUTH_SECRET: your-secret
|
||
NEXTAUTH_URL: https://configvault.yourdomain.com
|
||
ADMIN_USERNAME: admin
|
||
ADMIN_PASSWORD_HASH: $2a$12$...
|
||
NEXT_PUBLIC_APP_URL: https://configvault.yourdomain.com
|
||
depends_on: [db]
|
||
db:
|
||
image: postgres:16
|
||
environment:
|
||
POSTGRES_DB: configvault
|
||
POSTGRES_PASSWORD: password
|
||
volumes:
|
||
- pgdata:/var/lib/postgresql/data
|
||
- ./schema.sql:/docker-entrypoint-initdb.d/schema.sql
|
||
volumes:
|
||
pgdata:
|
||
```
|
||
|
||
---
|
||
|
||
## React Native — Kullanım
|
||
|
||
Uygulamanın içinde `lib/config.ts` oluştur:
|
||
|
||
```typescript
|
||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||
|
||
const CONFIG_URL = 'https://configvault.yourdomain.com/api/v1/config'
|
||
const APP_API_KEY = 'buraya_dashboard_api_key' // Dashboard > App > API Key tab
|
||
|
||
export async function initConfig(env = 'production') {
|
||
try {
|
||
const res = await fetch(`${CONFIG_URL}?env=${env}`, {
|
||
headers: { 'X-Api-Key': APP_API_KEY },
|
||
})
|
||
if (!res.ok) throw new Error('Config fetch failed')
|
||
const config = await res.json()
|
||
|
||
// Offline fallback için cache
|
||
await AsyncStorage.setItem('app_config', JSON.stringify(config))
|
||
return config
|
||
} catch {
|
||
const cached = await AsyncStorage.getItem('app_config')
|
||
if (cached) return JSON.parse(cached)
|
||
throw new Error('No config available')
|
||
}
|
||
}
|
||
```
|
||
|
||
`App.tsx`:
|
||
```typescript
|
||
import { initConfig } from './lib/config'
|
||
import { createClient } from '@supabase/supabase-js'
|
||
|
||
let supabase: any
|
||
|
||
export default function App() {
|
||
useEffect(() => {
|
||
initConfig('production').then(config => {
|
||
supabase = createClient(config.SUPABASE_URL, config.SUPABASE_ANON_KEY)
|
||
// artık config.ICON_URL, config.API_ENDPOINT vs. kullanabilirsin
|
||
})
|
||
}, [])
|
||
}
|
||
```
|
||
|
||
**Config değişince:** Dashboard'a gir → ilgili key'i güncelle → kaydet.
|
||
Tüm kullanıcılar bir sonraki açılışta yeni değeri alır. Rebuild yok. 🎉
|
||
|
||
---
|
||
|
||
## Yeni özellik ekleme
|
||
|
||
**Yeni config tipi:** `schema.sql` → `type CHECK` + `types/index.ts` + `AppDetailClient.tsx` select
|
||
|
||
**Yeni tablo/özellik:**
|
||
1. `schema.sql`'e ekle, `psql` ile migrate et
|
||
2. `app/api/apps/[id]/` altına route ekle
|
||
3. Dashboard'a tab/section ekle
|