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.
So my question is How to run my app on production to get running service worker?
I can’t move service-worker into public folder because of imports inside the file.
Thanks in advance.
Vladislav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.