I am trying to deploy a ReactJS service on GKE. I used Nginx to build my react images (I used create-react-app, and react router).
This is my dockerfile
FROM node:8.9.3-alpine as build-deps2
RUN mkdir /irooltest WORKDIR /irooltest COPY . /irooltest
RUN npm install RUN npm run build
FROM nginx:1.12-alpine
COPY --from=build-deps2 /irooltest/build /usr/share/nginx/html
EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
and this my docker compose file:
services:
irooltest:
image: chaimaennar/irooltest
ports:
- 8080:80
networks:
default:
networks:
default:
external:
name: mynetwork
I tried to export my application to ports other than 80, but I was not able to ( I got that this is due to nginx which is my default configured to serve on port 80).
Another issue is when running my application it only shows the root page, any other (route that I defined with react router) shows:
404 Not Found nginx/1.12.2
When I see the source (in the inspection section in the browser) I see this:
-Top
-localhost:8080
-static
-index.css
-Webpack://
Under the webpack I am able to see all my folders (code).
These are my routes:
<Route path="/home" render={(props) => <Layout auth={auth} {...props} />} />
<Route path="/" render={(props) => <App auth={auth} {...props} />} />
<Route path="/logo" render={(props) => <Logo />} />
<Route path="/callback" render={(props) => {
handleAuthentication(props);
return <Callback {...props} /> }}/>
<Route path="/profile" render={(props) => (<Profile auth={auth} {...props}/>
)
} />
<Route path="/user" render={(props) => <UserForm auth={auth} {...props} />} />
</div>
</Router>
My question is:
Is that a normal behavior?
Should it be a special configuration for nginx to serve the routes?