-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
93 lines (79 loc) · 2.32 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
const express = require("express");
const app = express();
const path = require("path");
const port = process.env.PORT || 3000;
const axios = require("axios");
const cors = require("cors");
require("dotenv").config();
var bodyParser = require("body-parser");
app.use(cors());
app.use(express.urlencoded({ extended: true }));
const { response } = require("express");
app.use(express.static("public"));
const token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2Mzc2ZTc5ZmZkOWFhYzIyNjczOTczMDIiLCJpYXQiOjE2NzE2MTc2NzgsImV4cCI6MTY3MTcwNDA3OH0.IZ0FtFtzeXtqEjG7jIeaZpyl32OkRZOppsRL3VIwPZc";
var tokens;
app.get("/login", async (req, res) => {
let user = {
email: process.env.EMAIL,
password: process.env.PASSWORD,
};
const options = {
method: "POST",
body: JSON.stringify(user),
headers: {
"Content-Type": "application/json",
},
};
const api_url = `http://api.cup2022.ir/api/v1/user/login`;
const fetch_response = await fetch(api_url, options);
const json = await fetch_response.json();
res.json(json);
console.log(json.data.token);
tokens = json.data.token;
});
app.get("/api/standings", async (req, res) => {
const options = {
method: "GET",
headers: {
Authorization: token,
"Content-Type": "application/json",
},
};
const api_url = `http://api.cup2022.ir/api/v1/standings/`;
const fetch_response = await fetch(api_url, options);
const json = await fetch_response.json();
res.json(json);
// console.log(json);
});
app.get("/api/match", async (req, res) => {
const options = {
method: "GET",
headers: {
Authorization: token,
"Content-Type": "application/json",
},
};
const api_url = `http://api.cup2022.ir/api/v1/match/`;
const fetch_response = await fetch(api_url, options);
const json = await fetch_response.json();
res.json(json);
// console.log(json);
});
app.get("/api/team", async (req, res) => {
const options = {
method: "GET",
headers: {
Authorization: token,
"Content-Type": "application/json",
},
};
const api_url = `http://api.cup2022.ir/api/v1/team/`;
const fetch_response = await fetch(api_url, options);
const json = await fetch_response.json();
res.json(json);
// console.log(json);
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});