React app using Docker and Nginx not showing assets with Redirect when 404

Viewed 300

I'm encountering a problem when deploying React (Create-react-app) using Docker, My setup is, Docker builds the React app and serves it using Nginx.

The Nginx config looks as follows:

        root /usr/share/nginx/html;

        location / {
            try_files $uri /index.html;
        }

And the DockerFile looks like:

FROM node:10-alpine as build-deps
WORKDIR /usr/src/front
COPY package*.json ./

RUN npm install
COPY . ./
RUN npm run build

FROM nginx:1.12-alpine
COPY --from=build-deps /usr/src/front/build /usr/share/nginx/html
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Which works when trying to access: www.myreactapp.com/something to www.myreactapp.com/ so that is correct behaviour, but then every assets inside: /public/images/ or /public/fonts/ doesn't show anymore.

Per example this logo doesnt show and no errors on the console:

src={`${Config.APP_URL}/images/icons/logo.svg`}

Anybody could help pin-point a solution? Thank you

0 Answers
Related