File tree Expand file tree Collapse file tree 6 files changed +52
-9
lines changed Expand file tree Collapse file tree 6 files changed +52
-9
lines changed Original file line number Diff line number Diff line change 1515npm-debug.log *
1616yarn-debug.log *
1717yarn-error.log *
18-
18+ keys.json
Original file line number Diff line number Diff line change 11import compression from 'compression' ;
22import express from 'express' ;
3+ import fs from 'fs' ;
4+ import request from 'request' ;
35
46const app = express ( ) ;
57const port = process . env . PORT || 8080 ;
68app . use ( compression ( ) ) ;
79
8- app . use ( express . static ( './build' ) ) ;
10+ let keys ;
11+ if ( fs . existsSync ( './keys.json' ) ) {
12+ keys = require ( './keys.json' ) ;
13+ } else {
14+ keys = JSON . parse ( process . env . VCAP_SERVICES ) [ 'user-provided' ] [ 0 ] . credentials ;
15+ }
16+
17+ app . get ( '/github' , ( req , res ) => {
18+ request ( {
19+ url : `https://api.github.com/user/repos?affiliation=owner,collaborator&access_token=${ keys . github } ` ,
20+ headers : {
21+ 'user-agent' : 'node.js' ,
22+ } ,
23+ } , ( err , response , body ) => {
24+ if ( ! err && response . statusCode === 200 ) {
25+ res . send ( body ) ;
26+ }
27+ } ) ;
28+ } ) ;
929
30+ app . use ( express . static ( './build' ) ) ;
1031app . listen ( port , ( err ) => {
11- if ( err ) {
12- console . log ( err ) ;
13- return ;
14- }
15- console . log ( `Server is live at http://localhost:${ port } ` ) ;
32+ if ( err ) {
33+ console . log ( err ) ;
34+ return ;
35+ }
36+ console . log ( `Server is live at http://localhost:${ port } ` ) ;
1637} ) ;
Original file line number Diff line number Diff line change @@ -5,3 +5,5 @@ applications:
55 command : npm run bluemix
66 disk_quota : 256MB
77 memory : 128MB
8+ services :
9+ - keys
Original file line number Diff line number Diff line change 99 "compression" : " ^1.6.2" ,
1010 "express" : " ^4.15.2" ,
1111 "react" : " ^15.4.2" ,
12- "react-dom" : " ^15.4.2"
12+ "react-dom" : " ^15.4.2" ,
13+ "request" : " ^2.80.0"
1314 },
1415 "devDependencies" : {
1516 "babel-watch" : " ^2.0.6" ,
Original file line number Diff line number Diff line change @@ -3,6 +3,23 @@ import logo from './logo.svg';
33import './App.css' ;
44
55class App extends Component {
6+
7+ state = {
8+ repos : [ ] ,
9+ }
10+
11+ componentDidMount ( ) {
12+ fetch ( '/github' )
13+ . then ( response => response . json ( ) )
14+ . then ( ( data ) => {
15+ const repos = data . map ( ( repo ) =>
16+ < p key = { repo . id } > { repo . name } </ p >
17+ ) ;
18+
19+ this . setState ( { repos } )
20+ } ) ;
21+ }
22+
623 render ( ) {
724 return (
825 < div className = "App" >
@@ -13,6 +30,8 @@ class App extends Component {
1330 < p className = "App-intro" >
1431 To get started, edit < code > src/App.js</ code > and save to reload.
1532 </ p >
33+ < h3 > App Creator's Repos:</ h3 >
34+ { this . state . repos }
1635 </ div >
1736 ) ;
1837 }
Original file line number Diff line number Diff line change @@ -4638,7 +4638,7 @@ repeating@^2.0.0:
46384638 dependencies :
46394639 is-finite "^1.0.0"
46404640
4641- request@^2.79.0 :
4641+ request, request @^2.79.0 :
46424642 version "2.80.0"
46434643 resolved "https://registry.yarnpkg.com/request/-/request-2.80.0.tgz#8cc162d76d79381cdefdd3505d76b80b60589bd0"
46444644 dependencies :
You can’t perform that action at this time.
0 commit comments