Skip to content

Commit e72b6d6

Browse files
committed
node-fetch replace with axios
1 parent 6e530b9 commit e72b6d6

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

lib/server.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const app = express()
33
const netApi = require('./proxy.js')
44
const port = process.env.PORT || 8080
55
const cors = require('cors')
6-
const fetch = require('node-fetch')
6+
const axios = require('axios');
77

88
app.use(cors())
99
app.use(netApi({ allowOrigin: '*' }))
@@ -13,21 +13,23 @@ app.use("/proxyCheck",(req,res,next)=>{
1313
})
1414

1515
app.get("/getId",(req,res,next)=>{
16-
fetch(`https://api.mojang.com/users/profiles/minecraft/${req.query.nick}`)
17-
.then(data => data.json())
18-
.then(player => {res.send(player.id)})
19-
.catch(error =>{
20-
res.send("ERR")
21-
})
16+
axios.get(`https://api.mojang.com/users/profiles/minecraft/${req.query.nick}`,{responseType: 'json'})
17+
.then(function (response) {
18+
res.send(response.data.id)
19+
})
20+
.catch(function (error) {
21+
res.send("ERR")
22+
})
2223
})
2324

2425
app.get("/getSkin",(req,res,next)=>{
25-
fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${req.query.id}?legacy=true`)
26-
.then(data => data.json())
27-
.then(player => {res.json(player)})
28-
.catch(error =>{
29-
res.send("ERR")
30-
})
26+
axios.get(`https://sessionserver.mojang.com/session/minecraft/profile/${req.query.id}?legacy=true`,{responseType: 'json'})
27+
.then(function (response) {
28+
res.json(response.data)
29+
})
30+
.catch(function (error) {
31+
res.send("ERR")
32+
})
3133
})
3234

3335
app.listen(port, () => {

package-lock.json

Lines changed: 27 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"node": "14.x"
2929
},
3030
"dependencies": {
31+
"axios": "^0.24.0",
3132
"body-parser": "^1.19.0",
3233
"cors": "^2.8.5",
3334
"crypto": "^1.0.1",

0 commit comments

Comments
 (0)