chore: durcit la configuration pour la production
- mobile: externalise l'URL d'API via EXPO_PUBLIC_API_URL (repli localhost en dev) - backend: .env.example adapté au projet (PostgreSQL, JWT, FRONTEND_URL, Redis) - frontend/mobile: ajoute .env.example (+ exception gitignore front) - mobile: supprime les 4 `any` (helper getApiError, type Feed, glyphMap Ionicons) - backend: normalise le style PSR-12 via Pint (13 fichiers) Tests backend 15/15, mobile tsc 0, Pint pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+25
-6
@@ -1,12 +1,31 @@
|
||||
import axios from 'axios';
|
||||
import axios, { isAxiosError } from 'axios';
|
||||
import * as SecureStore from 'expo-secure-store';
|
||||
import { Platform } from 'react-native';
|
||||
|
||||
const API_URL = Platform.select({
|
||||
android: 'http://10.0.2.2:8000/api/v1',
|
||||
ios: 'http://localhost:8000/api/v1',
|
||||
default: 'http://localhost:8000/api/v1',
|
||||
});
|
||||
/** Forme standard d'une réponse d'erreur de l'API Laravel. */
|
||||
export interface ApiErrorData {
|
||||
message?: string;
|
||||
errors?: Record<string, string[] | string>;
|
||||
}
|
||||
|
||||
/** Extrait proprement le corps d'erreur d'une exception (sans recourir à `any`). */
|
||||
export function getApiError(error: unknown): ApiErrorData {
|
||||
if (isAxiosError(error)) {
|
||||
return (error.response?.data as ApiErrorData) ?? {};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// En production, définir EXPO_PUBLIC_API_URL (ex. https://api.cesizen.fr/api/v1)
|
||||
// dans l'environnement de build (eas.json / .env). À défaut, on retombe sur la
|
||||
// configuration de développement local par plateforme (émulateur Android = 10.0.2.2).
|
||||
const API_URL =
|
||||
process.env.EXPO_PUBLIC_API_URL ||
|
||||
Platform.select({
|
||||
android: 'http://10.0.2.2:8000/api/v1',
|
||||
ios: 'http://localhost:8000/api/v1',
|
||||
default: 'http://localhost:8000/api/v1',
|
||||
});
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: API_URL,
|
||||
|
||||
Reference in New Issue
Block a user