File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -17,13 +17,28 @@ const app = express();
17
17
// Application
18
18
app . get ( '/' , function ( req , res ) {
19
19
if ( process . env . NODE_ENV === 'development' ) {
20
- for ( var key in require . cache ) {
21
- delete require . cache [ key ] ;
22
- }
20
+ // This doesn't work in ESM mode.
21
+ // for (var key in require.cache) {
22
+ // delete require.cache[key];
23
+ // }
23
24
}
24
25
require ( './handler.server.js' ) ( req , res ) ;
25
26
} ) ;
26
27
28
+ app . get ( '/todos' , function ( req , res ) {
29
+ res . setHeader ( 'Access-Control-Allow-Origin' , '*' ) ;
30
+ res . json ( [
31
+ {
32
+ id : 1 ,
33
+ text : 'Shave yaks' ,
34
+ } ,
35
+ {
36
+ id : 2 ,
37
+ text : 'Eat kale' ,
38
+ } ,
39
+ ] ) ;
40
+ } ) ;
41
+
27
42
app . listen ( 3001 , ( ) => {
28
43
console . log ( 'Flight Server listening on port 3001...' ) ;
29
44
} ) ;
Original file line number Diff line number Diff line change 1
1
import * as React from 'react' ;
2
+ import { fetch } from 'react-fetch' ;
2
3
3
4
import Container from './Container.js' ;
4
5
@@ -8,11 +9,17 @@ import {Counter as Counter2} from './Counter2.client.js';
8
9
import ShowMore from './ShowMore.client.js' ;
9
10
10
11
export default function App ( ) {
12
+ const todos = fetch ( 'http://localhost:3001/todos' ) . json ( ) ;
11
13
return (
12
14
< Container >
13
15
< h1 > Hello, world</ h1 >
14
16
< Counter />
15
17
< Counter2 />
18
+ < ul >
19
+ { todos . map ( todo => (
20
+ < li key = { todo . id } > { todo . text } </ li >
21
+ ) ) }
22
+ </ ul >
16
23
< ShowMore >
17
24
< p > Lorem ipsum</ p >
18
25
</ ShowMore >
You can’t perform that action at this time.
0 commit comments