PageSourceSearch

https://mens-eminal.jp/reserve/assets/js/api_client.js?v=1779417259

js mens-eminal.jp collected 2026-09-30 22:32:31 UTC 3,479 bytes, 75 lines download raw bytes

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.