【发布时间】:2020-01-01 18:04:51
【问题描述】:
我创建了免费的 IBM Cloud Kubernetes 集群,并尝试从 Docker 映像中部署我的 react pwa(使用 create-react-app 创建)。我设法在集群中部署了应用程序,但我的 service worker 不工作。
当我执行npm run build 和serve -s build 时,应用程序中的一切都在 localhost:5000 中正常工作。
但在已部署的应用程序中,在导航器中找不到 serviceWorker,并且它从不注册 serviceWorker:
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
...
//never goes in here
registerValidSW(swUrl, config);
});
在尝试访问已部署应用程序中的缓存时也会出现此错误:
Uncaught (in promise) ReferenceError: caches is not defined
at c (runtime.js:45)
at Generator._invoke (runtime.js:264)
at Generator.O.forEach.e.<computed> [as next] (runtime.js:98)
at r (asyncToGenerator.js:3)
at l (asyncToGenerator.js:25)
at asyncToGenerator.js:32
at new Promise (<anonymous>)
at t.getRequests (asyncToGenerator.js:21)
at t.value (index.js:142)
我的 Dockerfile 如下所示:
FROM node:alpine as builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx
EXPOSE 80
COPY --from=builder /app/build /usr/share/nginx/html
我的 deployment.yaml 看起来像这样:
apiVersion: v1
kind: Service
metadata:
name: my-app-service
labels:
app: app
spec:
type: NodePort
ports:
- port: 80
name: http
selector:
app: app
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-app-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: app
spec:
containers:
- name: my-app
image: us.icr.io/my-app-namespace/my-app
ports:
- containerPort: 8080
【问题讨论】:
标签: reactjs kubernetes ibm-cloud service-worker progressive-web-apps