mirror of
https://github.com/facebook/react.git
synced 2026-02-26 17:15:06 +00:00
* Rename pipeToNodeWritable to renderToNodePipe * Add startWriting API to Flight We don't really need it in this case because there's way less reason to delay the stream in Flight. * Pass the destination to startWriting instead of renderToNode * Rename startWriting to pipe This mirrors the ReadableStream API in Node * Error codes * Rename to renderToPipeableStream This mimics the renderToReadableStream API for the browser.
32 lines
882 B
JavaScript
32 lines
882 B
JavaScript
'use strict';
|
|
|
|
const {renderToPipeableStream} = require('react-server-dom-webpack/writer');
|
|
const {readFile} = require('fs');
|
|
const {resolve} = require('path');
|
|
const React = require('react');
|
|
|
|
module.exports = function(req, res) {
|
|
// const m = require('../src/App.server.js');
|
|
import('../src/App.server.js').then(m => {
|
|
const dist = process.env.NODE_ENV === 'development' ? 'dist' : 'build';
|
|
readFile(
|
|
resolve(__dirname, `../${dist}/react-client-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);
|
|
const {pipe} = renderToPipeableStream(
|
|
React.createElement(App),
|
|
moduleMap
|
|
);
|
|
pipe(res);
|
|
}
|
|
);
|
|
});
|
|
};
|