MCPcopy Index your code
hub / github.com/react/react / renderApp

Function renderApp

fixtures/flight/server/global.js:89–227  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

87}
88
89async function renderApp(req, res, next) {
90 // Proxy the request to the regional server.
91 const proxiedHeaders = {
92 'X-Forwarded-Host': req.hostname,
93 'X-Forwarded-For': req.ips,
94 'X-Forwarded-Port': 3000,
95 'X-Forwarded-Proto': req.protocol,
96 };
97 // Proxy other headers as desired.
98 if (req.get('rsc-action')) {
99 proxiedHeaders['Content-type'] = req.get('Content-type');
100 proxiedHeaders['rsc-action'] = req.get('rsc-action');
101 } else if (req.get('Content-type')) {
102 proxiedHeaders['Content-type'] = req.get('Content-type');
103 }
104 if (req.headers['cache-control']) {
105 proxiedHeaders['Cache-Control'] = req.get('cache-control');
106 }
107 if (req.get('rsc-request-id')) {
108 proxiedHeaders['rsc-request-id'] = req.get('rsc-request-id');
109 }
110
111 const requestsPrerender = req.path === '/prerender';
112
113 const promiseForData = request(
114 {
115 host: '127.0.0.1',
116 port: 3001,
117 method: req.method,
118 path: requestsPrerender ? '/?prerender=1' : '/',
119 headers: proxiedHeaders,
120 },
121 req
122 );
123
124 if (req.accepts('text/html')) {
125 try {
126 const rscResponse = await promiseForData;
127
128 let virtualFs;
129 let buildPath;
130 if (process.env.NODE_ENV === 'development') {
131 const {devMiddleware} = res.locals.webpack;
132 virtualFs = devMiddleware.outputFileSystem.promises;
133 buildPath = devMiddleware.stats.toJson().outputPath;
134 } else {
135 virtualFs = fs;
136 buildPath = path.join(__dirname, '../build/');
137 }
138 // Read the module map from the virtual file system.
139 const serverConsumerManifest = JSON.parse(
140 await virtualFs.readFile(
141 path.join(buildPath, 'react-ssr-manifest.json'),
142 'utf8'
143 )
144 );
145
146 // Read the entrypoints containing the initial JS to bootstrap everything.

Callers

nothing calls this directly

Calls 9

joinMethod · 0.80
setMethod · 0.80
onMethod · 0.80
requestFunction · 0.70
getMethod · 0.65
errorMethod · 0.65
writeMethod · 0.65
createFromNodeStreamFunction · 0.50
renderToPipeableStreamFunction · 0.50

Tested by

no test coverage detected