-
Notifications
You must be signed in to change notification settings - Fork 47.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Flight] End-to-End Fixture (#17319)
- Loading branch information
Showing
9 changed files
with
10,031 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SKIP_PREFLIGHT_CHECK=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "flight", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@babel/register": "^7.7.0", | ||
"concurrently": "^5.0.0", | ||
"express": "^4.17.1", | ||
"react-scripts": "3.2.0" | ||
}, | ||
"scripts": { | ||
"prestart": "cp -r ../../build/node_modules/* ./node_modules/", | ||
"prebuild": "cp -r ../../build/node_modules/* ./node_modules/", | ||
"start": "concurrently \"npm run start:server\" \"npm run start:client\"", | ||
"start:client": "react-scripts start", | ||
"start:server": "NODE_ENV=development node server", | ||
"start:prod": "react-scripts build && NODE_ENV=production node server", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": "react-app" | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<title>Flight</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const ReactFlightDOMServer = require('react-dom/unstable-flight-server'); | ||
const React = require('react'); | ||
const Stream = require('stream'); | ||
|
||
function Text({children}) { | ||
return <span>{children}</span>; | ||
} | ||
|
||
function HTML() { | ||
return ( | ||
<div> | ||
<Text>Hello</Text> | ||
<Text>world</Text> | ||
</div> | ||
); | ||
} | ||
|
||
module.exports = function(req, res) { | ||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
let model = { | ||
content: { | ||
__html: <HTML />, | ||
}, | ||
}; | ||
ReactFlightDOMServer.pipeToNodeWritable(model, res); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
const babelRegister = require('@babel/register'); | ||
|
||
babelRegister({ | ||
ignore: [/\/(build|node_modules)\//], | ||
presets: ['react-app'], | ||
}); | ||
|
||
const express = require('express'); | ||
const app = express(); | ||
|
||
// Application | ||
app.get('/', function(req, res) { | ||
if (process.env.NODE_ENV === 'development') { | ||
for (var key in require.cache) { | ||
delete require.cache[key]; | ||
} | ||
} | ||
require('./handler')(req, res); | ||
}); | ||
|
||
app.listen(3001, () => { | ||
console.log('Flight Server listening on port 3001...'); | ||
}); | ||
|
||
app.on('error', function(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
|
||
var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; | ||
|
||
switch (error.code) { | ||
case 'EACCES': | ||
console.error(bind + ' requires elevated privileges'); | ||
process.exit(1); | ||
break; | ||
case 'EADDRINUSE': | ||
console.error(bind + ' is already in use'); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React, {Suspense} from 'react'; | ||
|
||
function Content({data}) { | ||
return <p dangerouslySetInnerHTML={data.model.content} />; | ||
} | ||
|
||
function App({data}) { | ||
return ( | ||
<Suspense fallback={<h1>Loading...</h1>}> | ||
<Content data={data} /> | ||
</Suspense> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import ReactFlightDOMClient from 'react-dom/unstable-flight-client'; | ||
import App from './App'; | ||
|
||
let data = ReactFlightDOMClient.readFromFetch(fetch('http://localhost:3001')); | ||
ReactDOM.render(<App data={data} />, document.getElementById('root')); |
Oops, something went wrong.