ReactSSREntry
ReactSSREntry(config) ⇒ Promise.<Result>
Determine and run a specific version of an entry
Returns: Promise.<Result>
- The entry chunk result
Param | Type | Description |
---|---|---|
config | Config | The entry config |
ReactSSREntry~Config : Object
Properties
Name | Type | Description |
---|---|---|
props | Object | The plain object to be passed to <App {...props} /> |
require | function | The require function for loading a node module |
workdir | string | The working directory holding all the JS entries |
url | URL | The URL object after parsing the request url |
version | string | The version of the JS entry to be executed |
ReactSSREntry~Result : Object
Properties
Name | Type | Description |
---|---|---|
body | string | The require function for loading a node module |
statusCode | number | The working directory holding all the JS entries |
Example
const path = require("path");
const express = require("express");
const app = express();
app.get(
"*",
async (req, res) => {
const reqUrl = url.parse(req.url, true);
const {body, statusCode} = await ReactSSREntry({
"require": __non_webpack_require__, // if you want to bundle it with webpack
"workdir": path.join(__dirname, "dist"),
"props": {"url": reqUrl},
"url": reqUrl,
"version": reqUrl.query.version || "default",
});
res.writeHead(
statusCode,
{
"Content-Type": "text/html"
}
)
res.end(body);
}
)
app.listen(8080);