Skip to content

Commit

Permalink
Merge pull request #7 from gigantz/ojr/prepare-package
Browse files Browse the repository at this point in the history
Packaging and renaming
  • Loading branch information
gigantz authored Feb 11, 2021
2 parents 2e41ef4 + 4da7b68 commit b4bdae4
Show file tree
Hide file tree
Showing 41 changed files with 808 additions and 1,410 deletions.
13 changes: 11 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"presets": ["@babel/preset-env"],
"presets": [
[
"@babel/preset-env",
{
"targets": {
"esmodules": true
}
}
]
],
"plugins": ["@babel/plugin-transform-react-jsx"]
}
}
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"jsx-a11y/alt-text": 0,
"import/prefer-default-export": 0,
"import/no-extraneous-dependencies": 0
}
},
"ignorePatterns": "/lib"
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
.vscode
.vscode
.npmrc
dist
137 changes: 77 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,100 +1,117 @@
# ReactXpress
# Reactend / Express

**React renderer to build Node.js server**
React-like http-server on Nodejs
<br />

![Planet Express](public/logo.svg)
![Planet Express](./logo.svg)
<br/>

### Why?
## Why?

It's the only crazy idea to use React to structure Backend on Node.js.
<br />
<br /><br />

### How it works?
## How it works?

It works with express.js framework to run Node.js server. Custom renderer we have is building express structure app from React Components.
<br />
<br /><br />

## Install

### Install the package

`npm i --save @reactend/express`</br>
or</br>
`yarn add @reactend/express`</br>
<br/>

### Code Example
### Install peer dependecies

`npm i --save react react-dom react-helmet styled-components`</br>
or</br>
`yarn add react react-dom react-helmet styled-components`</br>

</br>

## Code Example

```js
import React from 'react';
import { resolve } from 'path';
import { ReactXpress, App, Static, Router, Get, Post, Res } from '../lib';

const HomePage = () => <h1>Home page</h1>;
const AboutPage = () => <h1>About Page</h1>;
import { registerApp, App, Static, Router, Get, Post, Res, Logger } from '@reactend/express';

const ExpressApp = () => (
<App port={process.env.PORT || 8080}>
<Static publicPath="/public" />
<Logger mode="dev" />
<Router path="/">
<Get render={HomePage} />
<Get path="/about" render={AboutPage} />
<Get>
<Res.Header name="Cache-Control" value="public, max-age=31557600" />
<Res.Render component={HomePage} />
</Get>
<Get path="/components" render={ComponentsPage} />
<Router path="/api">
<Post
path="/status"
json={{ msg: 'It is okay, bro' }}
handler={(req) => console.log(req.originalUrl)}
/>
</Router>
<Updates />
<Get path="*" text="Not Found" status={404} />
</Router>
</App>
);
```

// Updates! 🤩
const Updates = () => (
<>
<Get path="/redirect">
<Res.Redirect statusCode={301} path="https://ru.reactjs.org" />
</Get>
<Post path="/json">
<Res.Status statusCode={401} />
<Res.Content json={{ msg: 'No Access' }} contentType="application/json" />
</Post>
<Get path="/send-file">
<Res.SendFile path={resolve('public/code-example.png')} onError={console.log} />
</Get>
<Get path="/render">
<Res.Render component={() => <h1>Shut Up And Take My Money!</h1>} />
</Get>
</>
);
<br />

## You can use this way too

ReactXpress.render(<ExpressApp />);
```js
import cors from 'cors';
<Middleware handler={cors()} />;
```

### How to use

1. Clone the repo
2. `npm install`
3. Run dev mode - `npm run dev`
4. Do all changes in `./src` folder as it's not library yet.

### Components

`<App />` - App Instance (props: port)
`<Static />` - Static route (props: publicPath, path, options)
`<Router />` - Router-Provider (props: path)
`<Get />, <Post /> and ...` - Route component (props: path, content, handler, status)
`<Res />` - Response components
`<Res.Render />` - Render (props: component)
`<Res.Content />` - Response send (props: json, text, contentType)
`<Res.Status />` - Response Status (props: statusCode)
`<Res.SendFile />` - Response Send File (props: path, options, onError)
`<Res.Redirect />` - Redirect (props: path, statusCode)
```js
<Get path="/redirect">
<Res.Redirect statusCode={301} path="https://ru.reactjs.org" />
</Get>

<Post path="/json">
<Res.Status statusCode={401} />
<Res.Content json={{ msg: 'No Access' }} contentType="application/json" />
</Post>

<Get path="/send-file">
<Res.SendFile path={resolve('public/code-example.png')} onError={console.log} />
</Get>

<Get path="/render">
<Res.Render component={() => <h1>Shut Up And Take My Money!</h1>} />
</Get>
```

<br/>

## Components

_This minor description for now (Docs is on the way)_<br/><br/>
`<App />` - App Instance (props: port) <br />
`<Static />` - Static route (props: publicPath, path, options) <br />
`<Router />` - Router-Provider (props: path) <br />
`<Get />, <Post /> and ...` - Route component (props: path, content, <br />handler, status) <br />
`<Middleware />` - Middleware (props: handler) <br />
`<Logger />` - morgan logger (props: mode, disabled) <br />
`<Res />` - Response components <br />
`<Res.Render />` - Render (props: component) <br />
`<Res.Content />` - Response send (props: json, text, contentType) <br />
`<Res.Status />` - Response Status (props: statusCode) <br />
`<Res.SendFile />` - Response Send File (props: path, options, <br />onError) <br />
`<Res.Redirect />` - Redirect (props: path, statusCode) <br />
<br />
<br />

### What is planning?

I work on it and I'm trying to improve it, even it's not a good idea to use this kinda renderer for real-world app. But It would be awesome to have contributors to make its DX much better.

### Contact me
## Contact me

Email me if you have any idea and you would like to be contributor [[email protected]](mailto:[email protected])

Resources: <br/>
https://dev.to/orkhanjafarovr/express-in-react-react-backend-whut-4lkg
11 changes: 0 additions & 11 deletions examples/advanced/components.js

This file was deleted.

23 changes: 0 additions & 23 deletions examples/advanced/handlers.js

This file was deleted.

16 changes: 0 additions & 16 deletions examples/advanced/index.js

This file was deleted.

21 changes: 0 additions & 21 deletions examples/advanced/package-lock.json

This file was deleted.

15 changes: 0 additions & 15 deletions examples/advanced/package.json

This file was deleted.

20 changes: 0 additions & 20 deletions examples/basic/index.js

This file was deleted.

Loading

0 comments on commit b4bdae4

Please sign in to comment.