Skip to content

Commit 38de6e6

Browse files
committed
Fixture: Add fetch from a Server Component
1 parent 1426ec4 commit 38de6e6

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

fixtures/flight/server/cli.server.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,28 @@ const app = express();
1717
// Application
1818
app.get('/', function(req, res) {
1919
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+
// }
2324
}
2425
require('./handler.server.js')(req, res);
2526
});
2627

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+
2742
app.listen(3001, () => {
2843
console.log('Flight Server listening on port 3001...');
2944
});

fixtures/flight/src/App.server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import {fetch} from 'react-fetch';
23

34
import Container from './Container.js';
45

@@ -8,11 +9,17 @@ import {Counter as Counter2} from './Counter2.client.js';
89
import ShowMore from './ShowMore.client.js';
910

1011
export default function App() {
12+
const todos = fetch('http://localhost:3001/todos').json();
1113
return (
1214
<Container>
1315
<h1>Hello, world</h1>
1416
<Counter />
1517
<Counter2 />
18+
<ul>
19+
{todos.map(todo => (
20+
<li key={todo.id}>{todo.text}</li>
21+
))}
22+
</ul>
1623
<ShowMore>
1724
<p>Lorem ipsum</p>
1825
</ShowMore>

0 commit comments

Comments
 (0)