Skip to content

Commit 24b1bf4

Browse files
authored
Merge pull request #24 from SgtPooki/master
get example codebase working with claudiajs
2 parents 24c47a4 + d1fff3a commit 24b1bf4

Some content is hidden

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

45 files changed

+14095
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Universal React and serverless express with claudiajs
2+
3+
## What is this
4+
5+
This app is a combination of universal-create-react-app and aws-serverless-express as created from codestar, and it uses claudiajs to deploy the code changes to lambda. After weeks of trial and error, claudiajs helped me to fix a multitude of issues that I had with codestar, codebuild, and codecommit.
6+
7+
Please meet Claudiajs and appreciate the greatness.
8+
9+
## How to start
10+
1. https://claudiajs.com/tutorials/installing.html
11+
2. npm install
12+
3. Deploy a sample function with `npm run deploy-dev --profile $YOUR_AWS_PROFILE_NAME --name HelloWorldFunctionTest`
13+
4. You will get some output with a url to your function, as described here https://claudiajs.com/tutorials/hello-world-api-gateway.html#deploying-to-aws, and you should CMD/CTRL + Click on it.
14+
5. You should see the universal create react app landing page.
15+
16+
## How to test locally
17+
You should be able to follow the universal-create-react-app instructions. Please submit a PR or issue if you have trouble.
18+
19+
## How to deploy
20+
Deploy to prod with `npm run deploy-prod --profile $YOUR_AWS_PROFILE_NAME --name $YOUR_FUNCTION_NAME`
21+
Deploy to dev with `npm run deploy-dev --profile $YOUR_AWS_PROFILE_NAME --name $YOUR_FUNCTION_NAME`
22+
23+
## How to do other things
24+
Check out the documentation for claudiajs, universal-react-app, aws-serverless-express, and expressjs.
25+
26+
## Other notes
27+
28+
### Why steal universal-react-app readme?
29+
The readme from universal create react app is below (instead of simply being linked) so that you can read exactly how this was supposed to be used from the code that existed when this package was built.
30+
31+
### Whatsup with hot-reloading?
32+
I don't know. Hot reloading is a little bit slow because it has to compile first and there are a few other weird things I didn't care to take the time to fix. I don't know if I broke it or universal-create-react-app had it already partially sketchy.. but there is something wrong there and I would appreciate anyone who can fix it wherever the root cause is!
33+
34+
### Not all of my assets are loading..
35+
Yea... so, because of the production/development --version flag to claudiajs, the generated URL at first has some problems with the mappings. You can fix this by uncommenting the line in the config passed to ManifestPlugin. You will need to add logic to determine the appropriate production/development prefix. However, when you use API gateway and add a custom domain name, this issue is non-existent, so I didn't want to commit code that broke the usecase that is probably more common.
36+
37+
38+
## Universal Create React App
39+
40+
This project is a refactoring of the default app created by [create-react-app v1.0.7](https://github.com/facebookincubator/create-react-app/tree/v1.0.7), and then ejected.
41+
42+
A universal app runs both on the server and the client, and shares as much code as possible between the server and client - typically around 90%.
43+
44+
Development
45+
46+
![](https://gifyu.com/images/universal-dev.gif)
47+
48+
Production
49+
50+
![](https://gifyu.com/images/universal-build.gif)
51+
52+
For a step by step explanation read the article
53+
https://medium.com/leanjs/universal-create-react-app-step-by-step-b80ba68d125d
54+
55+
### How to run this project
56+
57+
- `yarn install`
58+
- `yarn start` to run it in development
59+
- `npm run build` to build the production bundle. You must build the production bundle before running the production bundle.
60+
- `npm run serve` to run the production bundle.
61+
- You can disable JavaScript on your browser, and use the app to test that the app is functional.
62+
- With JavaScript enabled and running the app in development mode (`yarn start`), you can test the CSS hot reloading by changing this file /src/client/index.css
63+
64+
### Explanation
65+
66+
The source code (src) is split in 3 folders:
67+
- client. This is code that runs just on the browser.
68+
- server. This is code that runs just on the server.
69+
- shared. This is code that runs both on the server and on the client
70+
71+
The server is implemented using [Express](http://expressjs.com/)
72+
73+
There are two build scripts. One to build the JavaScript bundle that will be sent to the client. By default from the same server but you could serve it via a CDN or anywhere else. The other build script builds the JavaScript bundle that runs on the server.
74+
- /scripts/build-client.js
75+
- /scripts/build-server.js
76+
77+
The start script will try to run the client (Webpack Dev Server) on a given port (3000 by default). If the port is not available it will try to find another port. We have implemented the same on the port used to run the server. The start script will try to run the server (Express compiled with Webpack) on a given port (5678 by default). If the port is not available it will try to find another port.
78+
79+
For a step by step explanation read the article
80+
https://medium.com/leanjs/universal-create-react-app-step-by-step-b80ba68d125d
81+
82+
### Features
83+
84+
All the features that you have in create-react-app are included in this project, plus react-router v4.
85+
86+
- `yarn start` will start two servers. The first one (Webpack Dev Server), to build and serve the JavaScript bundle to the client. The Second one (Express), to render the app on the server.
87+
- CSS Hot reloading is enabled. You'll notice a quick adjustment to the layout in development mode when you start the app. This is because while in development env the CSS is served via the Webpack Hot Module Replacement. So the app is rendered without CSS from the server, and then on the client it is injected when the JavaScript is run. If you run the app in production mode by executing `npm run serve` (note, you must first build the production bundle by executing `npm run build`), the CSS will be displayed from the beginning. The reason for this is that we don't hot replace the CSS in production.
88+
- "Page Not found" with a 404 status on the server-side without defining any route on the server.
89+
90+
### Acknowledgments
91+
92+
[Apollo GitHunt-React example](https://github.com/apollographql/GitHunt-React) was a great source of inspiration for finding solutions.
93+
94+
### README generated by create-react-app v1.0.7
95+
96+
You can read here the original README.md generated by create-react-app in this repo https://github.com/facebookincubator/create-react-app/blob/v1.0.7/packages/react-scripts/template/README.md
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"main.css": "production/static/css/main.cacbacc7.css",
3+
"main.css.map": "production/static/css/main.cacbacc7.css.map",
4+
"main.js": "production/static/js/main.fb8951f8.js",
5+
"main.js.map": "production/static/js/main.fb8951f8.js.map",
6+
"static/media/logo.svg": "production/static/media/logo.5d5d9eef.svg"
7+
}
24.3 KB
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "192x192",
8+
"type": "image/png"
9+
}
10+
],
11+
"start_url": "./index.html",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

web-serving-universal-react/build/client/service-worker.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web-serving-universal-react/build/client/static/css/main.cacbacc7.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web-serving-universal-react/build/client/static/css/main.cacbacc7.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web-serving-universal-react/build/client/static/js/main.fb8951f8.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web-serving-universal-react/build/client/static/js/main.fb8951f8.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)