Files
react/fixtures/flight/server/handler.server.js
T
Sebastian Markbåge 82e99e1b02 Add Node ESM Loader and Register Entrypoints (#20274)
* Add Node ESM loader build

This adds a loader build as a first-class export. This will grow in
complexity so it deserves its own module.

* Add Node CommonJS regiter build

This adds a build as a first-class export for legacy CommonJS registration
in Node.js. This will grow in complexity so it deserves its own module.

* Simplify fixture a bit to easier show usage with or without esm

* Bump es version

We leave async function in here which are newer than ES2015.
2020-11-16 23:46:27 -05:00

31 lines
824 B
JavaScript

'use strict';
import {pipeToNodeWritable} from 'react-transport-dom-webpack/server';
import * as React from 'react';
import url from 'url';
function resolve(path) {
return url.pathToFileURL(require.resolve(path)).href;
}
module.exports = async function(req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
const m = await import('../src/App.server.js');
// const m = require('../src/App.server.js');
const App = m.default.default || m.default;
pipeToNodeWritable(<App />, res, {
// TODO: Read from a map on the disk.
[resolve('../src/Counter.client.js')]: {
id: './src/Counter.client.js',
chunks: ['1'],
name: 'default',
},
[resolve('../src/ShowMore.client.js')]: {
id: './src/ShowMore.client.js',
chunks: ['2'],
name: 'default',
},
});
};