Skip to content

Commit

Permalink
Fix Flight Prod Fixture (#20382)
Browse files Browse the repository at this point in the history
* Don't use async/await

Babel transpilation fails for some reason in prod.

* Set up production runner command

Uses python because meh. Just to show it's static.

* Use build folder in prod
  • Loading branch information
sebmarkbage committed Dec 5, 2020
1 parent 3a8c04e commit 0db61a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
4 changes: 3 additions & 1 deletion fixtures/flight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
"start": "concurrently \"npm run start:server\" \"npm run start:client\"",
"start:client": "node scripts/start.js",
"start:server": "NODE_ENV=development node --experimental-loader ./loader/index.js --conditions=react-server server",
"start:prod": "node scripts/build.js && NODE_ENV=production node server",
"start:prod": "node scripts/build.js && concurrently \"npm run start:prod-server\" \"npm run start:prod-client\"",
"start:prod-client": "cd ./build && python -m SimpleHTTPServer 3000",
"start:prod-server": "NODE_ENV=production node --experimental-loader ./loader/index.js --conditions=react-server server",
"build": "node scripts/build.js",
"test": "node scripts/test.js --env=jsdom"
},
Expand Down
31 changes: 19 additions & 12 deletions fixtures/flight/server/handler.server.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
'use strict';

import {pipeToNodeWritable} from 'react-transport-dom-webpack/server';
import {readFileSync} from 'fs';
import {readFile} from 'fs';
import {resolve} from 'path';
import * as React from 'react';

module.exports = async function(req, res) {
const m = await import('../src/App.server.js');
module.exports = function(req, res) {
// const m = require('../src/App.server.js');
const App = m.default.default || m.default;
res.setHeader('Access-Control-Allow-Origin', '*');
const moduleMap = JSON.parse(
readFileSync(
resolve(__dirname, '../dist/react-transport-manifest.json'),
'utf8'
)
);
pipeToNodeWritable(<App />, res, moduleMap);
import('../src/App.server.js').then(m => {
const dist = process.env.NODE_ENV === 'development' ? 'dist' : 'build';
readFile(
resolve(__dirname, `../${dist}/react-transport-manifest.json`),
'utf8',
(err, data) => {
if (err) {
throw err;
}

const App = m.default.default || m.default;
res.setHeader('Access-Control-Allow-Origin', '*');
const moduleMap = JSON.parse(data);
pipeToNodeWritable(<App />, res, moduleMap);
}
);
});
};

0 comments on commit 0db61a0

Please sign in to comment.