https://github.com/frojd/hastur
Small node http server for rendering of react components
https://github.com/frojd/hastur
node react server-side-rendering
Last synced: 5 months ago
JSON representation
Small node http server for rendering of react components
- Host: GitHub
- URL: https://github.com/frojd/hastur
- Owner: Frojd
- License: mit
- Created: 2017-08-22T06:09:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T20:49:46.000Z (about 3 years ago)
- Last Synced: 2024-04-15T02:44:28.467Z (almost 2 years ago)
- Topics: node, react, server-side-rendering
- Language: JavaScript
- Size: 450 KB
- Stars: 13
- Watchers: 15
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hastur
A small node http server for rendering of react components (must be transpiled if using experimental features not found in node.js)
## Requirements
- Node.js > 8.x
## Installation & start
1. npm install git://github.com/Frojd/Hastur.git
2. node hastur.js
or
1. Use docker image: frojd/hastur
## Server configurations
As env variables:
```
HASTUR_PATH=/path/to/components/
HASTUR_PORT=3000
HASTUR_HOST=0.0.0.0
HASTUR_DEBUG=true
HASTUR_SENTRY=https://xxxx:yyyy@sentry.io/1234
HASTUR_JSON_SNAKE_TO_CAMEL=true
HASTUR_STRIP_DOT_PREFIX=true
```
or as parameters:
node app.js --port 3000 --host 0.0.0.0 --path /path/to/components/ --sentry https://xxxx:yyyy@sentry.io/1234 --debug --toCamelFromSnake --stripDotPrefix
## How to use
When started without any parameters, Hastur will accept application/json http POST request at http://localhost:3000 with this body:
```json
{
"componentName": "MyComponent",
"props": {
"title": "my props title",
"anyProp": "another prop"
},
"static": false,
"context": {
"location": "https://mysite.com",
"otherContext": "foo"
}
}
```
The above request will try to do a require(`componentName`) and render it with the passed along `props`.
If `HASTUR_PATH` is set, it will be prepended to the `componentName`.
**`static` (optional, default: false):**
If true, Hastur will return html without react bindings
**`context` (optional, default: undefined)**
If you need to pass along things that otherwise would not be included on the server side (such as request-info)
you can pass it along in the `context` attribute:
```json
{
"location": "https://somesite.com/foo"
}
```
You can access it in your components via the `SSRContext` object, allowing you to do stuff like:
```js
const currentURL = SSRContext.location ? SSRContext.location : window.location;
if (currentURL.search(/foo/)) {
console.log('The requested URL contains "foo"');
}
```
<<<<<<< Updated upstream
## How to build components
Components is easiest built through babel-cli:
```
.\node_modules\.bin\babel componentsfolder --out-dir raw --no-babelrc --plugins=transform-class-properties,transform-object-rest-spread --presets=react,env
```
=======
>>>>>>> Stashed changes
## Extras
Comes by default with optional sentry logging, if you do not plan to use it, please install with the `--no-optional` flag