Skip to content

Commit 8f0eff0

Browse files
Add spinner text and updated README file
1 parent 4f44878 commit 8f0eff0

File tree

6 files changed

+71
-36
lines changed

6 files changed

+71
-36
lines changed

.env-sample

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ REACT_APP_GOOGLE_AUTH_CLIENT_ID=23432543654-m4s23i3dsf72938gubrj32n8932ro9knqudv
1313
REACT_APP_PORT=3000
1414

1515
REACT_CLIENT_URL=http://localhost:3000
16-
REACT_APP_ENVIRONMENT=<prod/dev>
17-
ACTIVE_PROFILE=<dev/prod>
16+
REACT_APP_ENVIRONMENT=dev
17+
ACTIVE_PROFILE=dev
1818

1919
REDIS_PASSWORD=mypass
2020
REDIS_PORT=6379
2121

2222
AUTHENTICATION_SERVICE_PORT=7000
2323
PAYMENT_SERVICE_PORT=9050
2424
COMMON_DATA_SERVICE_PORT=9000
25-
SEARCH_SUGGESTION_SERVICE_PORT=10000
25+
SEARCH_SUGGESTION_SERVICE_PORT=10000

README.md

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,36 @@ eCommerce application based on the microservices architecture built using Spring
5151
**Steps for executing the application using docker-compose:**
5252
1. Clone/Download the repository.
5353

54+
5455
2. Set the environmental variables which will be impacted on docker-compose.yml.
55-
You can checkthe .env-sample file. Most of the variables are already set.
56-
You need to modify the variable and rename the file to ".env".
57-
You need to create a Stripe account and Google OAuth credentials.
58-
These accounts doesn't charge you anything and are absolutely free.
59-
60-
You need to set below two env variables.
61-
62-
REACT_APP_STRIPE_PUBLISH_KEY=<Your Stripe Publishable Key>
63-
64-
Go [Here](https://dashboard.stripe.com/register) to create a Stripe account.
65-
66-
REACT_APP_GOOGLE_AUTH_CLIENT_ID=<Your Google AUTH Client ID>
67-
68-
Go [Here](https://console.developers.google.com) to create Google OAuth Credentials.
56+
57+
1. You can check the .env-sample file. Most of the variables are already set.
58+
You need to rename the file ".env-sample" to ".env".
59+
<br/><br/>
60+
2. In addition, You need to create a Stripe account and Google OAuth credentials.
61+
The application works even if you don't create this account, only the payment and OAuth functionality will not work.
62+
These accounts doesn't charge you anything and are absolutely free.<br/><br/>
63+
64+
You need to set below two env variables.<br/><br/>
65+
66+
REACT_APP_STRIPE_PUBLISH_KEY=<Your Stripe Publishable Key>
67+
68+
Go [Here](https://dashboard.stripe.com/register) to create a Stripe account.
69+
<br/><br/>
70+
REACT_APP_GOOGLE_AUTH_CLIENT_ID=<Your Google AUTH Client ID>
71+
72+
Go [Here](https://console.developers.google.com) to create Google OAuth Credentials.
73+
74+
75+
3. Set the CORS in the backend service as shown below.
76+
```
77+
go to file on this path => server/common-data-service/src/main/java/com/ujjaval/ecommerce/commondataservice/config/CorsConfig.java
78+
79+
public void addCorsMappings(CorsRegistry registry) {
80+
registry.addMapping("/**").allowedOrigins(<Add your client host URL string here>)
81+
.allowedMethods("GET", "POST");
82+
}
83+
```
6984

7085
3. Build all the microservices and run the app using docker-compose. This is done using ./start-all.sh script which creates the network and set the container dependencies based on the config mention in the docker-compose.yml.
7186
This will build all the jar files and run all the services.
@@ -74,7 +89,7 @@ eCommerce application based on the microservices architecture built using Spring
7489
```
7590

7691
4. If you are making any change in the code then you need to you ./stop-all.sh to clean up the jars created by ./start-all.sh script. Also, you need to remove the images from the docker otherwise it will occupy the image spaces unnecessarily.
77-
92+
<br/><br/>
7893
You can check docker images with below command
7994
```
8095
docker images
@@ -86,22 +101,25 @@ eCommerce application based on the microservices architecture built using Spring
86101

87102
**Payment Service Test Details:**
88103

89-
Credit card no.: 4242 4242 4242 4242
90-
Expiry: Any future date
91-
CVV: Any 3-digit number
104+
Credit card no.: 4242 4242 4242 4242
105+
Expiry: Any future date
106+
CVV: Any 3-digit number
92107

93108
**Steps to deploy on Heroku using docker-compose:**
94109

95110
1. create heroku.yml as docker-compose.yml is not invoked on Heroku.
96111

112+
97113
2. If the application contains a database then install MySQL or any other database
98-
from Heroku marketplace[https://elements.heroku.com].
99-
114+
from Heroku marketplace[https://elements.heroku.com].
115+
<br/><br/>
100116
Note: Before installing you need to add credit/debit card info. Without this it
101117
won't allow you to install the database.
102118

119+
103120
3. Set the config vars based on the database URL.
104121

122+
105123
4. Set the stack:container for the application in order to build with docker-compose.
106124
```
107125
heroku stack:set container -a <application-name>

client/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
work correctly both with client-side routing and a non-root public URL.
2727
Learn how to configure a non-root public URL by running `npm run build`.
2828
-->
29-
<title>React App</title>
29+
<title>Welcome to Shoppers</title>
3030
</head>
3131
<body>
3232
<noscript>You need to enable JavaScript to run this app.</noscript>

client/src/components/routes/home/home.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {HOME_PAGE_DATA_API} from "../../../constants/api_routes";
1818
import {HOME_PAGE_API_OBJECT_LEN} from "../../../constants/constants"
1919
import {authServiceAPI} from "../../../api/service_api";
2020
import axios from "axios";
21+
import {Grid} from "@material-ui/core";
2122

2223
const Home = props => {
2324
const {hover} = useSelector(state => state.tabHoverEventReducer)
@@ -32,22 +33,23 @@ const Home = props => {
3233
// Heroku so that it serves the requests quickly.
3334
// This should be removed when the app is deployed on actual server.
3435
props.setDefaultSearchSuggestions()
35-
authServiceAPI.post('/authenticate').catch(err => {})
36-
if(process.env.REACT_APP_PAYMENT_SERVICE_URL) {
36+
authServiceAPI.post('/authenticate').catch(err => {
37+
})
38+
if (process.env.REACT_APP_PAYMENT_SERVICE_URL) {
3739
axios({
3840
method: 'post',
39-
url: `${process.env.REACT_APP_PAYMENT_SERVICE_URL}/payment`,
41+
url: `${process.env.REACT_APP_PAYMENT_SERVICE_URL}/payment`,
4042
headers: {
4143
'Content-Type': 'application/json',
4244
},
4345
data: "xyz"
44-
}).catch(err => {})
46+
}).catch(err => {
47+
})
4548
}
4649
///////////////////////////////////////////////////////////
4750

4851

49-
50-
if(!homeAPIData.hasOwnProperty("data")) {
52+
if (!homeAPIData.hasOwnProperty("data")) {
5153
props.getDataViaAPI(LOAD_HOME_PAGE, HOME_PAGE_DATA_API, null, false);
5254
}
5355

@@ -57,7 +59,19 @@ const Home = props => {
5759
// we will be showing spinner till we get the data via API
5860
if (homeAPIData.isLoading) {
5961
log.info("[Home]: loading")
60-
return <Spinner/>
62+
return <Spinner textComponent={
63+
<Grid container direction="column" spacing={1} style={{
64+
alignItems: "center", fontSize: "1.1rem", fontWeight: "bold"}}>
65+
<Grid item>
66+
Please wait! This will take 1-2 minutes to load page for the first time.
67+
</Grid>
68+
<Grid item>
69+
The backend service on heroku was in sleep mode and now its started.
70+
</Grid>
71+
<Grid item>
72+
It will sleep again if the backend service is inactive for 30 minutes.
73+
</Grid>
74+
</Grid>}/>
6175
} else {
6276

6377
// check if we got the data from the API
@@ -97,4 +111,4 @@ const Home = props => {
97111
)
98112
}
99113

100-
export default connect(null, {getDataViaAPI, setDefaultSearchSuggestions})(Home);
114+
export default connect(null, {getDataViaAPI, setDefaultSearchSuggestions})(Home);

client/src/components/ui/spinner.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import React from 'react';
22
import CircularProgress from '@material-ui/core/CircularProgress';
33
import {Box} from "@material-ui/core";
44

5-
export default function Spinner() {
5+
export default function Spinner({textComponent = null}) {
66
return (
7-
<Box display="flex" justifyContent="center" alignItems="center" css={{ minHeight: "60vh"}}>
8-
<CircularProgress color="secondary"/>
7+
<Box display="flex" justifyContent="center" alignItems="center"
8+
css={{minHeight: "60vh", flexDirection: "column"}}>
9+
10+
<CircularProgress color="secondary" style={{marginBottom: 20}}/>
11+
{textComponent}
912
</Box>
1013
);
1114
}

server/common-data-service/src/main/java/com/ujjaval/ecommerce/commondataservice/config/CorsConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CorsConfig implements WebMvcConfigurer
1111
{
1212
@Override
1313
public void addCorsMappings(CorsRegistry registry) {
14-
registry.addMapping("/**").allowedOrigins(System.getenv("REACT_CLIENT_URL"))
14+
registry.addMapping("/**").allowedOrigins("https://shoppers-ecom-app.herokuapp.com")
1515
.allowedMethods("GET", "POST");
1616
}
1717
}

0 commit comments

Comments
 (0)