Skip to content

Commit b4bdae4

Browse files
authored
Merge pull request #7 from gigantz/ojr/prepare-package
Packaging and renaming
2 parents 2e41ef4 + 4da7b68 commit b4bdae4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+808
-1410
lines changed

.babelrc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2-
"presets": ["@babel/preset-env"],
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"esmodules": true
8+
}
9+
}
10+
]
11+
],
312
"plugins": ["@babel/plugin-transform-react-jsx"]
4-
}
13+
}

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"jsx-a11y/alt-text": 0,
1313
"import/prefer-default-export": 0,
1414
"import/no-extraneous-dependencies": 0
15-
}
15+
},
16+
"ignorePatterns": "/lib"
1617
}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
.vscode
2+
.vscode
3+
.npmrc
4+
dist

README.md

Lines changed: 77 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,117 @@
1-
# ReactXpress
1+
# Reactend / Express
22

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

6-
![Planet Express](public/logo.svg)
6+
![Planet Express](./logo.svg)
7+
<br/>
78

8-
### Why?
9+
## Why?
910

1011
It's the only crazy idea to use React to structure Backend on Node.js.
11-
<br />
12+
<br /><br />
1213

13-
### How it works?
14+
## How it works?
1415

1516
It works with express.js framework to run Node.js server. Custom renderer we have is building express structure app from React Components.
16-
<br />
17+
<br /><br />
18+
19+
## Install
20+
21+
### Install the package
22+
23+
`npm i --save @reactend/express`</br>
24+
or</br>
25+
`yarn add @reactend/express`</br>
26+
<br/>
1727

18-
### Code Example
28+
### Install peer dependecies
29+
30+
`npm i --save react react-dom react-helmet styled-components`</br>
31+
or</br>
32+
`yarn add react react-dom react-helmet styled-components`</br>
33+
34+
</br>
35+
36+
## Code Example
1937

2038
```js
2139
import React from 'react';
2240
import { resolve } from 'path';
23-
import { ReactXpress, App, Static, Router, Get, Post, Res } from '../lib';
2441

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

2844
const ExpressApp = () => (
2945
<App port={process.env.PORT || 8080}>
3046
<Static publicPath="/public" />
47+
<Logger mode="dev" />
3148
<Router path="/">
32-
<Get render={HomePage} />
33-
<Get path="/about" render={AboutPage} />
49+
<Get>
50+
<Res.Header name="Cache-Control" value="public, max-age=31557600" />
51+
<Res.Render component={HomePage} />
52+
</Get>
53+
<Get path="/components" render={ComponentsPage} />
3454
<Router path="/api">
3555
<Post
3656
path="/status"
3757
json={{ msg: 'It is okay, bro' }}
3858
handler={(req) => console.log(req.originalUrl)}
3959
/>
4060
</Router>
41-
<Updates />
4261
<Get path="*" text="Not Found" status={404} />
4362
</Router>
4463
</App>
4564
);
65+
```
4666

47-
// Updates! 🤩
48-
const Updates = () => (
49-
<>
50-
<Get path="/redirect">
51-
<Res.Redirect statusCode={301} path="https://ru.reactjs.org" />
52-
</Get>
53-
<Post path="/json">
54-
<Res.Status statusCode={401} />
55-
<Res.Content json={{ msg: 'No Access' }} contentType="application/json" />
56-
</Post>
57-
<Get path="/send-file">
58-
<Res.SendFile path={resolve('public/code-example.png')} onError={console.log} />
59-
</Get>
60-
<Get path="/render">
61-
<Res.Render component={() => <h1>Shut Up And Take My Money!</h1>} />
62-
</Get>
63-
</>
64-
);
67+
<br />
68+
69+
## You can use this way too
6570

66-
ReactXpress.render(<ExpressApp />);
71+
```js
72+
import cors from 'cors';
73+
<Middleware handler={cors()} />;
6774
```
6875

69-
### How to use
70-
71-
1. Clone the repo
72-
2. `npm install`
73-
3. Run dev mode - `npm run dev`
74-
4. Do all changes in `./src` folder as it's not library yet.
75-
76-
### Components
77-
78-
`<App />` - App Instance (props: port)
79-
`<Static />` - Static route (props: publicPath, path, options)
80-
`<Router />` - Router-Provider (props: path)
81-
`<Get />, <Post /> and ...` - Route component (props: path, content, handler, status)
82-
`<Res />` - Response components
83-
`<Res.Render />` - Render (props: component)
84-
`<Res.Content />` - Response send (props: json, text, contentType)
85-
`<Res.Status />` - Response Status (props: statusCode)
86-
`<Res.SendFile />` - Response Send File (props: path, options, onError)
87-
`<Res.Redirect />` - Redirect (props: path, statusCode)
76+
```js
77+
<Get path="/redirect">
78+
<Res.Redirect statusCode={301} path="https://ru.reactjs.org" />
79+
</Get>
80+
81+
<Post path="/json">
82+
<Res.Status statusCode={401} />
83+
<Res.Content json={{ msg: 'No Access' }} contentType="application/json" />
84+
</Post>
85+
86+
<Get path="/send-file">
87+
<Res.SendFile path={resolve('public/code-example.png')} onError={console.log} />
88+
</Get>
89+
90+
<Get path="/render">
91+
<Res.Render component={() => <h1>Shut Up And Take My Money!</h1>} />
92+
</Get>
93+
```
94+
95+
<br/>
96+
97+
## Components
98+
99+
_This minor description for now (Docs is on the way)_<br/><br/>
100+
`<App />` - App Instance (props: port) <br />
101+
`<Static />` - Static route (props: publicPath, path, options) <br />
102+
`<Router />` - Router-Provider (props: path) <br />
103+
`<Get />, <Post /> and ...` - Route component (props: path, content, <br />handler, status) <br />
104+
`<Middleware />` - Middleware (props: handler) <br />
105+
`<Logger />` - morgan logger (props: mode, disabled) <br />
106+
`<Res />` - Response components <br />
107+
`<Res.Render />` - Render (props: component) <br />
108+
`<Res.Content />` - Response send (props: json, text, contentType) <br />
109+
`<Res.Status />` - Response Status (props: statusCode) <br />
110+
`<Res.SendFile />` - Response Send File (props: path, options, <br />onError) <br />
111+
`<Res.Redirect />` - Redirect (props: path, statusCode) <br />
88112
<br />
89113
<br />
90114

91-
### What is planning?
92-
93-
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.
94-
95-
### Contact me
115+
## Contact me
96116

97117
Email me if you have any idea and you would like to be contributor [orkhanjafarovr@gmail.com](mailto:orkhanjafarovr@gmail.com)
98-
99-
Resources: <br/>
100-
https://dev.to/orkhanjafarovr/express-in-react-react-backend-whut-4lkg

examples/advanced/components.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/advanced/handlers.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

examples/advanced/index.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/advanced/package-lock.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/advanced/package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/basic/index.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)