docs: Tambahkan instruksi deployment CORS dan troubleshooting
This commit is contained in:
@@ -58,7 +58,19 @@ composer install --no-dev --optimize-autoloader
|
||||
# 3. Regenerate autoloader
|
||||
composer dump-autoload --optimize
|
||||
|
||||
# 4. Clear cache (jika ada)
|
||||
# 4. Update .env dengan konfigurasi CORS (jika belum ada)
|
||||
# Edit .env dan tambahkan:
|
||||
# CORS_ALLOWED_ORIGINS=*
|
||||
# CORS_ALLOWED_METHODS=GET,POST,PUT,DELETE,OPTIONS
|
||||
# CORS_ALLOWED_HEADERS=Content-Type,Authorization,X-API-KEY,Accept,Origin
|
||||
# CORS_ALLOW_CREDENTIALS=true
|
||||
|
||||
# 5. Restart PHP-FPM (opsional, untuk memastikan perubahan ter-load)
|
||||
# Via aaPanel: Website -> PHP -> Service Management -> Reload
|
||||
# Atau via command:
|
||||
# systemctl reload php-fpm-83 # Sesuaikan dengan PHP version
|
||||
|
||||
# 6. Clear cache (jika ada)
|
||||
# Tidak ada cache untuk project ini, skip
|
||||
```
|
||||
|
||||
@@ -163,6 +175,14 @@ JWT_ISSUER=api-btekno
|
||||
|
||||
# API Key
|
||||
RETRIBUSI_API_KEY=generate-secure-api-key-here
|
||||
|
||||
# CORS (Cross-Origin Resource Sharing)
|
||||
# Untuk development: gunakan '*' untuk allow semua origin
|
||||
# Untuk production: list origin yang diizinkan dipisah koma
|
||||
CORS_ALLOWED_ORIGINS=*
|
||||
CORS_ALLOWED_METHODS=GET,POST,PUT,DELETE,OPTIONS
|
||||
CORS_ALLOWED_HEADERS=Content-Type,Authorization,X-API-KEY,Accept,Origin
|
||||
CORS_ALLOW_CREDENTIALS=true
|
||||
```
|
||||
|
||||
**Generate secure keys:**
|
||||
@@ -236,6 +256,58 @@ chown -R www:www /www/wwwroot/api.btekno.cloud/api
|
||||
chmod -R 755 /www/wwwroot/api.btekno.cloud/api
|
||||
```
|
||||
|
||||
### Error: CORS belum dikonfigurasi / CORS error di browser
|
||||
|
||||
**Cause**: CORS middleware belum ter-deploy atau konfigurasi `.env` belum ada
|
||||
**Solution**:
|
||||
|
||||
1. **Pastikan code terbaru sudah di-pull:**
|
||||
```bash
|
||||
cd /www/wwwroot/api.btekno.cloud/api
|
||||
git pull origin main
|
||||
composer dump-autoload --optimize
|
||||
```
|
||||
|
||||
2. **Pastikan `.env` sudah ada konfigurasi CORS:**
|
||||
```bash
|
||||
nano /www/wwwroot/api.btekno.cloud/api/.env
|
||||
```
|
||||
|
||||
Tambahkan (atau pastikan sudah ada):
|
||||
```env
|
||||
CORS_ALLOWED_ORIGINS=*
|
||||
CORS_ALLOWED_METHODS=GET,POST,PUT,DELETE,OPTIONS
|
||||
CORS_ALLOWED_HEADERS=Content-Type,Authorization,X-API-KEY,Accept,Origin
|
||||
CORS_ALLOW_CREDENTIALS=true
|
||||
```
|
||||
|
||||
3. **Restart PHP-FPM:**
|
||||
```bash
|
||||
# Via aaPanel: Website -> PHP -> Service Management -> Reload
|
||||
# Atau via command (sesuaikan PHP version):
|
||||
systemctl reload php-fpm-83
|
||||
```
|
||||
|
||||
4. **Test CORS dari browser console:**
|
||||
```javascript
|
||||
fetch('https://api.btekno.cloud/health', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => console.log('CORS OK:', data))
|
||||
.catch(err => console.error('CORS Error:', err));
|
||||
```
|
||||
|
||||
5. **Cek response headers:**
|
||||
```bash
|
||||
curl -I -H "Origin: http://localhost:3000" https://api.btekno.cloud/health
|
||||
```
|
||||
|
||||
Harus ada header `Access-Control-Allow-Origin` di response.
|
||||
|
||||
## 📊 Monitoring
|
||||
|
||||
- Check logs: `/www/wwwroot/api.btekno.cloud/api/logs/` (jika ada)
|
||||
|
||||
Reference in New Issue
Block a user