1// ========================================================= 2// ð <ããã³ãå´> çµ±åAPI: api_client.js 3// ========================================================= 4 5// ð ç°å¢æ¤ç¥ã»ã³ãµã¼ï¼URLãã©ã¡ã¼ã¿ã« '?debug=on' ãå«ã¾ãã¦ãããï¼ 6const _apiParams = new URLSearchParams(window.location.search); 7const isTestEnv = (_apiParams.get('debug') === 'on'); 8 9// ð APIã®æ¥ç¶å ãèªååãæ¿ãï¼ 10const API_BASE_URL = isTestEnv 11 ? 'https://demo.main.epi-reserve.com/reserve/api/reserve' // ð§ ãã¹ãç°å¢ç¨ 12 : 'https://epi-reserve.com/reserve/api/reserve'; // ð¢ æ¬çªç°å¢ç¨ 13 14/** 15 * éä¿¡ã³ãã³ã: callApi 16 * 17 * @param {string} endpoint - 'get_shops.php' ã®ãããªãã¡ã¤ã«åãã¾ã㯠'https://...' ããå§ã¾ããã«URL 18 * @param {FormData | Object | null} payload - FormDataãªãèªåã§POSTãObjectãªãèªåã§GETã®ãã©ã¡ã¼ã¿ã«ãªãã¾ã 19 * @returns {Promise<Object>} APIããã®JSONã¬ã¹ãã³ã¹ 20 */ 21async function callApi(endpoint, payload = null) { 22 // â ãURLèªåè£å®è½åããã«URLãç´æ¸ãããã¦ããã°ãã®ã¾ã¾ãããã§ãªããã°ãã¼ã¹URLã¨åä½ï¼ 23 let url = endpoint.startsWith('http') ? endpoint : `${API_BASE_URL}/${endpoint}`; 24 // ð 追å ï¼åºæ¬ã®ãªãã·ã§ã³ã« headers ãæºå 25 let options = { 26 method: 'GET', 27 headers: {} 28 }; 29 30 // ð¥ çªç ´é¨éï¼ãã¹ãç°å¢ãªããBasicèªè¨¼ã®åè¨èããããã¼ã«å¿ã°ããï¼ 31 if (isTestEnv) { 32 // â» é£ä¸ã®ç°å¢ã®IDã¨ãã¹ã¯ã¼ãã«æ¸ãæãã¦ãã ããï¼ 33 const basicId = 'demo'; 34 const basicPass = 'test'; 35 36 // btoa() ã¯ãIDã¨ãã¹ã¯ã¼ããBasicèªè¨¼ç¨ã®æå·(Base64)ã«å¤æããåªæã§ã 37 options.headers['Authorization'] = 'Basic ' + btoa(basicId + ':' + basicPass); 38 } 39 // â¡ ãèªåå µè£ åãæ¿ãè½åãæ¸¡ãããè·ç©ï¼payloadï¼ãè¦ã¦ãæ»ææ¹æ³ãå¤ããï¼ 40 if (payload) { 41 if (payload instanceof FormData) { 42 // è·ç©ãFormDataãªããåçç¡ç¨ã§ãPOSTå µè£ ãã«åãæ¿ãï¼ 43 options.method = 'POST'; 44 options.body = payload; 45 } else if (typeof payload === 'object' && !Array.isArray(payload)) { 46 // è·ç©ããªãã¸ã§ã¯ãï¼è¾æ¸ï¼ãªããURLã®æ«å°¾ã«ãã£ã¤ãã¦ãGETå µè£ ãï¼ 47 const params = new URLSearchParams(payload).toString(); 48 url += (url.includes('?') ? '&' : '?') + params; 49 } 50 } 51 52 // ãããã°ç¨ï¼ç¾å¨ã©ã®é¨éãã©ããã£ã¦éä¿¡ãã¦ãããã³ã³ã½ã¼ã«ã«å ±å 53 console.log(`[å¸ä»¤å¡ callApi] ð çªæéå§: ${url} (Method: ${options.method})`); 54 55 try { 56 const response = await fetch(url, options); 57 58 // ãããã¯ã¼ã¯ã¬ãã«ã®è´å½å·ï¼404ã500ï¼ã¯ããã§ãã£ããï¼ 59 if (!response.ok) { 60 throw new Error(`[HTTPã¨ã©ã¼] éä¿¡ã«å¤±æãã¾ãã (ã¹ãã¼ã¿ã¹: ${response.status})`); 61 } 62 63 // JSONã¸ã®ãã¼ã¹ãå¸ä»¤å¡ãè©ä»£ãããã¾ã 64 const result = await response.json(); 65 66 // æ¦æãåç·ã®é¨éã¸è¿ã 67 // â»ãã¸ãã¹ãã¸ãã¯ï¼status !== 'success'çã®å¤å®ï¼ã¯åç»é¢ã§ã¢ã©ã¼ãããªãã¤ã¬ã¯ãçã®æ¼åºãç°ãªããããåJSãã¡ã¤ã«ã«ä»»ãã¾ãã 68 return result; 69 70 } catch (error) { 71 console.error('[å¸ä»¤å¡ éä¿¡é害çºç] ð¥', error); 72 // åé¨éã®catchãããã¯ã¸ã¨ã©ã¼ãæµã 73 throw error; 74 } 75}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.