Skip to content

Commit 4f44878

Browse files
Moved CORS config to env variable
1 parent f0c53fa commit 4f44878

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

.env-sample

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ DB_PASS=mypass
1111
REACT_APP_STRIPE_PUBLISH_KEY=pk_test_51H805Oa3n3j3JVXUotWOsdf223PXI2ZehJ0s4QSQK0WjEJer78w87wer8h2u3bo32sTVcxyh5bDuulBildNrp
1212
REACT_APP_GOOGLE_AUTH_CLIENT_ID=23432543654-m4s23i3dsf72938gubrj32n8932ro9knqudv.apps.googleusercontent.com
1313
REACT_APP_PORT=3000
14-
REACT_APP_ENVIRONMENT=<prod/dev>
1514

15+
REACT_CLIENT_URL=http://localhost:3000
16+
REACT_APP_ENVIRONMENT=<prod/dev>
1617
ACTIVE_PROFILE=<dev/prod>
18+
1719
REDIS_PASSWORD=mypass
1820
REDIS_PORT=6379
1921

client/.env-sample

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
REACT_APP_STRIPE_PUBLISH_KEY=pk_test_5dsf4534jkmn4nm345QSQK0WjEJKx1PNH3mJxeUkA45345345Vcxyh5bDuulBildNrp3MWn005xEkAdJ4
2-
REACT_APP_COMMON_DATA_SERVICE_IP=localhost
32
REACT_APP_GOOGLE_AUTH_CLIENT_ID=357808142500-sdfsndln4oh5345435.apps.googleusercontent.com
3+
4+
# Add below ports if you are running on your machine
45
REACT_APP_AUTHENTICATION_SERVICE_PORT=7000
56
REACT_APP_PAYMENT_SERVICE_PORT=9050
67
REACT_APP_COMMON_DATA_SERVICE_PORT=9000
78
REACT_APP_SEARCH_SUGGESTION_SERVICE_PORT=10000
9+
REACT_APP_COMMON_DATA_SERVICE_IP=localhost
10+
11+
# Add URL if you dont want to use port.
12+
# Higher priority is given to URL over PORTs.
813
REACT_APP_AUTHENTICATION_SERVICE_URL=<URL of Auth Service>
914
REACT_APP_COMMON_DATA_SERVICE_URL=<URL of Common Data Service>
1015
REACT_APP_PAYMENT_SERVICE_URL=<URL of Payment Service>
1116
REACT_APP_SEARCH_SUGGESTION_SERVICE_URL=<URL of Search Suggestion Service>
17+
1218
REACT_APP_ENVIRONMENT=<prod/dev>

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- spring-cloud-microservices
1818

1919
redis-cache:
20-
image: redis:latest
20+
image: redis:alpine
2121
container_name: redis-cache-container
2222
command: redis-server --requirepass ${REDIS_PASSWORD}
2323
ports:
@@ -73,6 +73,7 @@ services:
7373
- REDIS_PASSWORD=${REDIS_PASSWORD}
7474
- REDIS_HOST=redis-cache
7575
- REDIS_PORT=${REDIS_PORT}
76+
- REACT_CLIENT_URL=${REACT_CLIENT_URL}
7677
links:
7778
- mysql-db:mysql
7879
expose:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public class CommonDataServiceApplication {
1212

1313
public static void main(final String[] args) {
1414
ConfigurableApplicationContext context = SpringApplication.run(CommonDataServiceApplication.class, args);
15-
// context.getBean(CommonDataController.class).fillWithTestData();
15+
context.getBean(CommonDataController.class).fillWithTestData();
1616
}
1717
}

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("https://shoppers-ecom-app.herokuapp.com")
14+
registry.addMapping("/**").allowedOrigins(System.getenv("REACT_CLIENT_URL"))
1515
.allowedMethods("GET", "POST");
1616
}
1717
}

0 commit comments

Comments
 (0)