1
1
const express = require ( 'express' ) ;
2
2
const router = express . Router ( )
3
- const axios = require ( 'axios' )
3
+ const { get , post } = require ( 'axios' )
4
4
var session = require ( 'express-session' )
5
5
const { github} = require ( './../../config/config' )
6
6
var clientId = github . clientId
7
7
var clientSecret = github . clientSecret
8
8
9
9
router . get ( '/getUserProfile' , ( req , res ) => {
10
10
username = req . query . username
11
- axios
12
- . get ( `https://api.github.com/users/${ username } ` )
11
+ get ( `https://api.github.com/users/${ username } ` )
13
12
. then ( resp => {
14
13
res . send ( resp . data )
15
14
} )
@@ -24,8 +23,7 @@ router.get('/getUserProfile',(req,res)=>{
24
23
console . log ( "username" , req . query . username )
25
24
if ( githubLogin == "false" ) {
26
25
console . log ( "! githubLogin is " , githubLogin )
27
- axios
28
- . get ( `https://api.github.com/users/${ username } /orgs` )
26
+ get ( `https://api.github.com/users/${ username } /orgs` )
29
27
. then ( resp => {
30
28
res . send ( resp . data )
31
29
} )
@@ -39,8 +37,7 @@ router.get('/getUserProfile',(req,res)=>{
39
37
}
40
38
}
41
39
console . log ( config )
42
- axios
43
- . get ( `https://api.github.com/user/orgs` , config = config )
40
+ get ( `https://api.github.com/user/orgs` , config = config )
44
41
. then ( resp => {
45
42
console . log ( resp . data . length )
46
43
return resp . data
@@ -52,8 +49,7 @@ router.get('/getUserProfile',(req,res)=>{
52
49
"Authorization" :`token ${ oauth_token } `
53
50
}
54
51
}
55
- axios
56
- . get ( `https://api.github.com/users/${ username } /orgs` , config = config )
52
+ get ( `https://api.github.com/users/${ username } /orgs` , config = config )
57
53
. then ( resp1 => {
58
54
console . log ( resp1 . data . length )
59
55
var flag , elem ;
@@ -86,16 +82,14 @@ router.get('/getUserProfile',(req,res)=>{
86
82
console . log ( config )
87
83
username = req . query . username
88
84
if ( username !== undefined ) {
89
- axios
90
- . get ( `https://api.github.com/users/${ username } /repos` , config = config )
85
+ get ( `https://api.github.com/users/${ username } /repos` , config = config )
91
86
. then ( resp => {
92
87
res . send ( resp . data )
93
88
} )
94
89
. catch ( err => res . json ( { "error" :err } ) )
95
90
}
96
91
else {
97
- axios
98
- . get ( `https://api.github.com/user/repos` , config = config )
92
+ get ( `https://api.github.com/user/repos` , config = config )
99
93
. then ( resp => {
100
94
res . send ( resp . data )
101
95
} )
@@ -114,8 +108,7 @@ router.get('/getUserProfile',(req,res)=>{
114
108
"Authorization" :`token ${ oauth_token } `
115
109
}
116
110
}
117
- axios
118
- . get ( `https://api.github.com/user` , config = config )
111
+ get ( `https://api.github.com/user` , config = config )
119
112
. then ( resp => {
120
113
res . cookie ( 'username' , resp . data [ "login" ] , { expires : new Date ( Date . now ( ) + + 315360000000 ) } ) //saves username for upcoming queries of logedin user
121
114
res . json ( resp . data )
@@ -124,8 +117,7 @@ router.get('/getUserProfile',(req,res)=>{
124
117
}
125
118
else {
126
119
console . log ( "not github login" )
127
- axios
128
- . get ( `https://api.github.com/users/${ username } ` )
120
+ get ( `https://api.github.com/users/${ username } ` )
129
121
. then ( resp => {
130
122
res . cookie ( 'username' , resp . data [ "login" ] , { expires : new Date ( Date . now ( ) + + 315360000000 ) } ) //saves username for upcoming queries of logedin user
131
123
res . json ( resp . data )
@@ -143,7 +135,7 @@ router.get('/auth',(req,res)=>{
143
135
} ;
144
136
145
137
const opts = { headers : { accept : 'application/json' } } ;
146
- axios . post ( `https://github.com/login/oauth/access_token` , body , opts ) .
138
+ post ( `https://github.com/login/oauth/access_token` , body , opts ) .
147
139
then ( res => {
148
140
return { token :res . data [ 'access_token' ] , refresh :res . data [ 'refresh_token' ] }
149
141
} )
@@ -173,8 +165,7 @@ router.get('/auth',(req,res)=>{
173
165
}
174
166
}
175
167
176
- axios
177
- . get ( `https://api.github.com/user` , config = config )
168
+ get ( `https://api.github.com/user` , config = config )
178
169
. then ( resp => {
179
170
res . cookie ( 'username' , resp . data [ "login" ] , { expires : new Date ( Date . now ( ) + + 315360000000 ) } ) //saves username for upcoming queries of logedin user
180
171
if ( resp . data . type == "User" ) {
0 commit comments