Initial commit of template
This commit is contained in:
23
utils/api.ts
Normal file
23
utils/api.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export function getApiUrl(path: string): string {
|
||||
const cleanPath = path.startsWith('/') ? path : `/${path}`;
|
||||
|
||||
if (typeof window !== 'undefined' && window.location) {
|
||||
const origin = window.location.origin;
|
||||
// Local Expo dev server direct port
|
||||
if (origin.includes(':8081')) {
|
||||
return `http://localhost:8080/api${cleanPath}`;
|
||||
}
|
||||
// Deployed Modal Sandbox direct port
|
||||
if (origin.includes('.modal.host') || origin.includes('.modal.run')) {
|
||||
const backendOrigin = origin.replace('-8081-', '-8080-').replace('-8081.modal.run', '-8080.modal.run');
|
||||
return `${backendOrigin}/api${cleanPath}`;
|
||||
}
|
||||
|
||||
// Relative path works when accessed via port 5173 /mobile proxy
|
||||
return `/api${cleanPath}`;
|
||||
}
|
||||
|
||||
// Fallback for native devices
|
||||
const baseUrl = process.env.EXPO_PUBLIC_API_URL || 'http://localhost:8080/api';
|
||||
return `${baseUrl}${cleanPath}`;
|
||||
}
|
||||
31
utils/crypto-setup.ts
Normal file
31
utils/crypto-setup.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'react-native-get-random-values';
|
||||
import 'react-native-url-polyfill/auto';
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
if (typeof global !== 'undefined') {
|
||||
if (typeof global.Buffer === 'undefined') {
|
||||
global.Buffer = Buffer;
|
||||
}
|
||||
} else if (typeof window !== 'undefined') {
|
||||
if (typeof (window as any).Buffer === 'undefined') {
|
||||
(window as any).Buffer = Buffer;
|
||||
}
|
||||
}
|
||||
|
||||
const { getRandomValues } = require('react-native-get-random-values');
|
||||
|
||||
if (typeof global !== 'undefined') {
|
||||
if (typeof global.crypto === 'undefined') {
|
||||
(global as any).crypto = {
|
||||
getRandomValues: getRandomValues,
|
||||
};
|
||||
}
|
||||
} else if (typeof window !== 'undefined') {
|
||||
if (typeof window.crypto === 'undefined') {
|
||||
(window as any).crypto = {
|
||||
getRandomValues: getRandomValues,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
Reference in New Issue
Block a user