File tree 3 files changed +53
-1
lines changed
3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ const app = express();
4
4
5
5
app . use ( express . static ( path . join ( `${ __dirname } /build` ) ) ) ;
6
6
7
- const port = process . env . PORT || 3000 ;
7
+ const port = process . env . PORT || 5000 ;
8
8
9
9
const server = app . listen ( port , ( ) => {
10
10
process . stdout . write ( `App listening on port ${ port } !\n Press CTR C to stop the server` )
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import logo from './logo.svg' ;
3
+ import ChucksJoke from './ChucksJoke'
3
4
import './App.css' ;
4
5
5
6
function App ( ) {
6
7
return (
7
8
< div className = "App" >
8
9
< header className = "App-header" >
9
10
< img src = { logo } className = "App-logo" alt = "logo" />
11
+ < ChucksJoke />
10
12
< p >
11
13
Edit < code > src/App.js</ code > and save to reload.
12
14
</ p >
Original file line number Diff line number Diff line change
1
+ import React from "react" ;
2
+
3
+ export default class ApiOne extends React . Component {
4
+ constructor ( ) {
5
+ super ( ) ;
6
+ this . state = {
7
+ joke : [ ]
8
+ } ;
9
+ }
10
+
11
+ componentDidMount ( ) {
12
+ const myHeaders = new Headers ( ) ;
13
+ myHeaders . append (
14
+ "X-RapidAPI-Host" ,
15
+ "matchilling-chuck-norris-jokes-v1.p.rapidapi.com"
16
+ ) ;
17
+ myHeaders . append (
18
+ "X-RapidAPI-Key" ,
19
+ "5456615b4cmsh40eaeb350692ccep17bbe1jsn2758aaa3f720"
20
+ ) ;
21
+ myHeaders . append ( "accept" , "application/json" ) ;
22
+
23
+ const myInit = { method : "GET" , headers : myHeaders } ;
24
+
25
+ const myRequest = new Request (
26
+ "https://matchilling-chuck-norris-jokes-v1.p.rapidapi.com/jokes/random" ,
27
+ myInit
28
+ ) ;
29
+
30
+ fetch ( myRequest )
31
+ . then ( res => res . json ( ) )
32
+ . then ( data =>
33
+ this . setState ( {
34
+ joke : data . value
35
+ } )
36
+ ) ;
37
+ }
38
+
39
+ render ( ) {
40
+ return (
41
+ < div className = "container" >
42
+ < h1 >
43
+ Ready to have your mind blown and be destroyed by a single Chuck
44
+ Norris joke!
45
+ </ h1 >
46
+ < h2 > { this . state . joke } </ h2 >
47
+ </ div >
48
+ ) ;
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments