웹 프론트 페이지 개발
- React + Vite 구성 - lotto-frontend 구성 - script 설정으로 nas server로 빌드 n 배포 수행
This commit is contained in:
39
src/api.js
Normal file
39
src/api.js
Normal file
@@ -0,0 +1,39 @@
|
||||
// src/api.js
|
||||
export async function apiGet(path) {
|
||||
const res = await fetch(path, { headers: { "Accept": "application/json" } });
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => "");
|
||||
throw new Error(`HTTP ${res.status} ${res.statusText}: ${text}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function apiDelete(path) {
|
||||
const res = await fetch(path, { method: "DELETE" });
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => "");
|
||||
throw new Error(`HTTP ${res.status} ${res.statusText}: ${text}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export function getLatest() {
|
||||
return apiGet("/api/lotto/latest");
|
||||
}
|
||||
|
||||
export function recommend(params) {
|
||||
const qs = new URLSearchParams({
|
||||
recent_window: String(params.recent_window),
|
||||
recent_weight: String(params.recent_weight),
|
||||
avoid_recent_k: String(params.avoid_recent_k),
|
||||
});
|
||||
return apiGet(`/api/lotto/recommend?${qs.toString()}`);
|
||||
}
|
||||
|
||||
export function getHistory(limit = 30) {
|
||||
return apiGet(`/api/history?limit=${limit}`);
|
||||
}
|
||||
|
||||
export function deleteHistory(id) {
|
||||
return apiDelete(`/api/history/${id}`);
|
||||
}
|
||||
Reference in New Issue
Block a user