File size: 1,884 Bytes
7f22d3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// API Configuration
// Configure the base URL for backend API
// If frontend and backend are deployed under the same domain, can be set to empty string or relative path
// If frontend and backend are deployed separately, need to set to full backend URL, e.g.: 'https://api.example.com'

const API_CONFIG = {
    // Backend API base URL
    baseURL: window.location.origin, // Default to current domain
    
    // WebSocket connection URL
    wsURL: (() => {
        const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
        return `${protocol}//${window.location.host}`;
    })(),
    
    // API endpoints
    endpoints: {
        search: '/api/search',
        feedback: '/api/feedback',
        trending: '/api/trending',
        feed: '/api/feed',
        item: '/api/item',
        upload: {
            url: '/api/upload/url',
            text: '/api/upload/text',
            image: '/api/upload/image'
        },
        admin: {
            browse: '/api/admin/browse',
            promote: '/api/admin/promote',
            delete: '/api/admin/delete',
            backfill: '/api/admin/backfill'
        }
    },
    
    // Get full API URL
    getURL: function(endpoint) {
        if (endpoint.startsWith('http://') || endpoint.startsWith('https://')) {
            return endpoint;
        }
        return `${this.baseURL}${endpoint}`;
    },
    
    // Get WebSocket URL
    getWebSocketURL: function(path = '/ws') {
        return `${this.wsURL}${path}`;
    }
};

// If you need to use different configurations for different environments, set it like this:
// if (window.location.hostname === 'localhost') {
//     API_CONFIG.baseURL = 'http://localhost:8000';
//     API_CONFIG.wsURL = 'ws://localhost:8000';
// } else {
//     API_CONFIG.baseURL = 'https://api.production.com';
//     API_CONFIG.wsURL = 'wss://api.production.com';
// }