Skip to content

Commit 34b19fa

Browse files
committed
move endpoints to config.js
1 parent 465a950 commit 34b19fa

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/pages/coc/config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// API configuration for Clash of Clans
2+
export const API_CONFIG = {
3+
BASE_URL: 'https://coc-apis.behitek.com',
4+
CLAN_TAG: '%232G9YRCRV2',
5+
endpoints: {
6+
currentWar: '/clans/{tag}/currentwar',
7+
clanInfo: '/clans/{tag}',
8+
warLeague: 'clans/{tag}/currentwar/leaguegroup'
9+
}
10+
};
11+
12+
// Helper function to format endpoints with clan tag
13+
export const getEndpoint = (endpoint) => {
14+
return `${API_CONFIG.BASE_URL}${endpoint.replace('{tag}', API_CONFIG.CLAN_TAG)}`;
15+
};

src/pages/coc/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Layout from '@theme/Layout';
22
import React, { useEffect, useState } from 'react';
3+
import { API_CONFIG, getEndpoint } from './config';
34
import styles from './styles.module.css';
45

56
export default function ClanProfile() {
@@ -16,7 +17,7 @@ export default function ClanProfile() {
1617
useEffect(() => {
1718
const fetchWarData = async () => {
1819
try {
19-
const response = await fetch('https://coc-apis.behitek.com/clans/%232G9YRCRV2/currentwar');
20+
const response = await fetch(getEndpoint(API_CONFIG.endpoints.currentWar));
2021
const warApiData = await response.json();
2122
setWarData(warApiData);
2223
} catch (err) {
@@ -30,7 +31,7 @@ export default function ClanProfile() {
3031
useEffect(() => {
3132
const fetchClanData = async () => {
3233
try {
33-
const response = await fetch('https://coc-apis.behitek.com/clans/%232G9YRCRV2');
34+
const response = await fetch(getEndpoint(API_CONFIG.endpoints.clanInfo));
3435
const data = await response.json();
3536
setClanData(data);
3637
setIsLoading(false);
@@ -217,7 +218,7 @@ export default function ClanProfile() {
217218
const button = event.currentTarget;
218219
button.classList.add(styles.processing);
219220
try {
220-
const response = await fetch('https://coc-apis.behitek.com/clans/%232G9YRCRV2/currentwar');
221+
const response = await fetch(getEndpoint(API_CONFIG.endpoints.currentWar));
221222
const warApiData = await response.json();
222223
setWarData(warApiData);
223224
button.classList.remove(styles.processing);

0 commit comments

Comments
 (0)