-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
81 lines (69 loc) · 2.32 KB
/
server.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const express = require("express");
const cors = require("cors"); // Import cors package
const DraftingAssistant = require("./drafting");
const app = express();
const draftingAssistant = new DraftingAssistant();
app.use(cors()); // Enable CORS for all routes
app.use(express.json());
app.post("/ban-hero", (req, res) => {
const { hero, isTeamBan } = req.body;
const result = draftingAssistant.banHero(hero, isTeamBan);
res.json({
message: result,
teamBans: draftingAssistant.teamBans,
enemyBans: draftingAssistant.enemyBans,
});
});
app.get("/recommend-ban", (req, res) => {
res.json({ recommendations: draftingAssistant.getBanRecommendation() });
});
app.post("/reset", (req, res) => {
draftingAssistant.resetDraft();
res.json({ message: "Drafting reset successfully." });
});
// app.post("/pick-hero", (req, res) => {
// const { hero, isTeamPick } = req.body;
// const result = draftingAssistant.pickHero(hero, isTeamPick);
// res.json({ message: result, currentPicks: draftingAssistant.currentPicks });
// });
// Endpoint untuk pick hero dengan saran strategi tambahan
app.post("/pick-hero", (req, res) => {
const { hero, isTeamPick } = req.body;
const result = draftingAssistant.pickHero(hero, isTeamPick);
// Memastikan bahwa result memiliki strategi
if (result.strategy) {
res.json({
message: result.message,
currentPicks: draftingAssistant.currentPicks,
strategy: result.strategy, // Mengembalikan strategi yang diambil
});
} else {
res.json({
message: result.message,
currentPicks: draftingAssistant.currentPicks,
strategy: null, // Jika tidak ada strategi, set null
});
}
});
app.get("/recommend-pick", (req, res) => {
const { isTeamPick } = req.query;
res.json({
recommendations: draftingAssistant.getPickRecommendation(
isTeamPick === "true"
),
});
});
app.get("/counter-hero", (req, res) => {
const { hero } = req.query;
res.json({ counters: draftingAssistant.getCounter(hero) });
});
// Endpoint khusus untuk mendapatkan strategi hero
app.get("/hero-strategy", (req, res) => {
const { hero, isTeam } = req.query;
const isTeamBoolean = isTeam === "true";
const strategy = draftingAssistant.getHeroStrategy(hero, isTeamBoolean);
res.json(strategy);
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});