1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  */
    
  8. 
    
  9. import * as React from 'react';
    
  10. import {renderToString} from 'react-dom/server';
    
  11. import App from '../src/App';
    
  12. import {API_DELAY, ABORT_DELAY} from './delays';
    
  13. import {performance} from 'perf_hooks';
    
  14. 
    
  15. // In a real setup, you'd read it from webpack build stats.
    
  16. let assets = {
    
  17.   'main.js': '/main.js',
    
  18.   'main.css': '/main.css',
    
  19. };
    
  20. 
    
  21. let textEncoder = new TextEncoder();
    
  22. 
    
  23. module.exports = function render(url, res) {
    
  24.   let payload =
    
  25.     '<!DOCTYPE html>' +
    
  26.     renderToString(<App assets={assets} />) +
    
  27.     '<script src="/main.js" async=""></script>';
    
  28.   let arr = textEncoder.encode(payload);
    
  29. 
    
  30.   let buf = Buffer.from(arr);
    
  31.   res.statusCode = 200;
    
  32.   res.setHeader('Content-type', 'text/html');
    
  33.   res.send(buf);
    
  34. };