Relative Content

Tag Archive for progressive-web-appsservice-worker

Service worker in the React JS project in the docker container

I’m trying to create notifications in my PWA app.
So I used npx create-react-app my-app –template cra-template-pwa to create my app.
My service-worker.js file is in the src directory as well as serviceWorkerRegistration.js. I register service worker in my index.js file with serviceWorkerRegistration.register();
So when I locally run “npm run build” and then “serve -s build” I can open my app locally and have working service worker.Everything works correctly.
Then I tried to deploy my app. I created dockerfile like:

FROM node:20-alpine as builder
WORKDIR /app
COPY package.json /app/package.json
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD [“npm”, “start”]”
But when I open my site, the service worker doesn’t work.