「Widget:Custom map」の版間の差分

提供:メタファー リファンタジオ 攻略Wiki
移動先:案内検索
編集の要約なし
編集の要約なし
26行目: 26行目:
// APIベースURLを定数として定義
// APIベースURLを定数として定義
const API_BASE_URL = 'https://prd-h1g-elb-2067013247.ap-northeast-1.elb.amazonaws.com/metaphor_refantazio';
const API_BASE_URL = 'https://prd-h1g-elb-2067013247.ap-northeast-1.elb.amazonaws.com/metaphor_refantazio';
///////////////////
// CORSデバッグ関数の定義
window.debugCORSIssues = function() {
    console.group('=== CORS Configuration Debug Info ===');
   
    // 基本情報の表示
    console.log('1. Basic Information:');
    console.log('Current page URL:', window.location.href);
    console.log('Current origin:', window.location.origin);
    console.log('Target API URL:', API_BASE_URL);
    console.log('Protocol match?', window.location.protocol === new URL(API_BASE_URL).protocol);
   
    // APIリクエストのテスト
    console.log('\n2. Testing API access...');
   
    $.ajax({
        url: API_BASE_URL + '/api.php',
        data: {
            action: 'query',
            meta: 'tokens',
            type: 'csrf',
            format: 'json'
        },
        method: 'GET',
        xhrFields: {
            withCredentials: true
        }
    })
    .done(function(response) {
        console.log('✅ API request successful!');
        console.log('Response:', response);
    })
    .fail(function(xhr, status, error) {
        console.error('❌ API request failed:', {
            status: xhr.status,
            statusText: xhr.statusText,
            error: error,
            response: xhr.responseText
        });
       
        if (xhr.status === 0) {
            console.error('🚫 This appears to be a CORS error.');
            console.error('Check server CORS configuration and ensure the following headers are set:');
            console.error('- Access-Control-Allow-Origin');
            console.error('- Access-Control-Allow-Credentials (if using cookies)');
            console.error('- Access-Control-Allow-Methods');
            console.error('- Access-Control-Allow-Headers');
        }
    })
    .always(function() {
        // レスポンスヘッダーの確認(可能な場合)
        console.log('\n3. Checking response headers...');
        try {
            $.ajax({
                url: API_BASE_URL + '/api.php',
                method: 'OPTIONS',
                complete: function(xhr) {
                    console.log('CORS Headers:', {
                        'Access-Control-Allow-Origin': xhr.getResponseHeader('Access-Control-Allow-Origin'),
                        'Access-Control-Allow-Methods': xhr.getResponseHeader('Access-Control-Allow-Methods'),
                        'Access-Control-Allow-Headers': xhr.getResponseHeader('Access-Control-Allow-Headers'),
                        'Access-Control-Allow-Credentials': xhr.getResponseHeader('Access-Control-Allow-Credentials')
                    });
                }
            });
        } catch (e) {
            console.error('Unable to check CORS headers:', e);
        }
    });
    // 現在のドメインとAPI URLの比較
    console.log('\n4. Domain comparison:');
    try {
        const currentUrl = new URL(window.location.href);
        const apiUrl = new URL(API_BASE_URL);
        console.log('Current domain:', currentUrl.hostname);
        console.log('API domain:', apiUrl.hostname);
        console.log('Same domain?', currentUrl.hostname === apiUrl.hostname);
        console.log('Same protocol?', currentUrl.protocol === apiUrl.protocol);
        console.log('Same port?', currentUrl.port === apiUrl.port);
    } catch (e) {
        console.error('Error comparing domains:', e);
    }
    console.log('\n5. Quick CORS checklist:');
    console.log('□ API_BASE_URL is correctly set');
    console.log('□ Server has CORS headers configured');
    console.log('□ Protocols match (both http or both https)');
    console.log('□ Credentials handling is properly configured');
    console.log('□ Required headers are allowed');
    console.groupEnd();
};
// ヘルプ機能を追加
window.showCORSHelp = function() {
    console.log(`
CORS Debugging Help:
------------------
1. Run 'debugCORSIssues()' to start debugging
2. Check for any red error messages
3. Verify the API URL is correct
4. Ensure protocols match (http/https)
5. Check server CORS configuration
Common Solutions:
--------------
1. Server needs to set Access-Control-Allow-Origin header
2. Use https for both client and server
3. Enable credentials if using cookies
4. Check API_BASE_URL configuration
`);
};
console.log('CORS debugging tools loaded. Type debugCORSIssues() to start debugging or showCORSHelp() for instructions.');
///////////////////


window.savePopupContent = savePopupContent;
window.savePopupContent = savePopupContent;

2024年11月10日 (日) 12:38時点における版