-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
3a8c04e
commit 0db61a0
Showing
2 changed files
with
22 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
); | ||
}); | ||
}; |