Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit d761575

Browse files
author
B1nj0y
committed
update README
1 parent 049c3d8 commit d761575

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,41 @@ Firstly, let's construct the routes for the two views in `application.jsx`.
217217
import React from 'react'
218218
import ReactDOM from 'react-dom'
219219
import { HashRouter, Route, Link } from 'react-router-dom'
220+
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
221+
import AppBar from 'material-ui/AppBar';
222+
223+
import IndexCard from './index'
224+
import ShowCard from './show'
225+
226+
// some routes
227+
228+
<Route exact path="/" component={Index}/>
229+
<Route path="/posts/:id" component={Show}/>
220230

221231
```
222232

223233
Here we use `HashRouter` instead of `Router` directive because we need the server-side render at first, `/path` will be an invalid route for Rails while `/#path` will be manipulated by frontend.
224234

225235

236+
And we'll created three React components to get the job done:
237+
238+
* [application.jsx](https://github.com/goonr/example_with_admin/blob/master/app/javascript/packs/application.jsx)
239+
* [index.jsx](https://github.com/goonr/example_with_admin/blob/master/app/javascript/packs/index.jsx)
240+
* [show.jsx](https://github.com/goonr/example_with_admin/blob/master/app/javascript/packs/show.jsx)
241+
242+
you can check the files to get the details.
243+
244+
Here we use a javascript package named `axios` to do Ajax requests, and it's easy to handle. You can install it by yarn:
245+
246+
```bash
247+
yarn add axios
248+
```
249+
250+
### Server side changes
251+
252+
Now we need set up Rails server to request APIs of our Go application, so we need to add CORS configuration to the Go server to make cross domains access. Because we use the Gin framework by default, so we choose a cors package for the Gin: github.com/gin-contrib/cors.
253+
254+
We just use its default configuration that allows all the Orgins can access our Go server for testing easily, here's [the details](https://github.com/gin-contrib/cors#default-allows-all-origins).
255+
256+
226257
(WIP)

app/javascript/packs/application.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import React from 'react'
22
import ReactDOM from 'react-dom'
33
import { HashRouter, Route, Link } from 'react-router-dom'
44
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
5+
import AppBar from 'material-ui/AppBar';
6+
57
import IndexCard from './index'
68
import ShowCard from './show'
7-
import AppBar from 'material-ui/AppBar';
89

910
const App = (props) => {
1011
return (

0 commit comments

Comments
 (0)