【发布时间】:2021-02-06 04:30:38
【问题描述】:
我正在基于 Next.js 示例应用程序工作,如下链接
https://github.com/vercel/next.js/tree/canary/examples/progressive-web-app
这是我的next.config.js
const withPWA = require('next-pwa')
const runtimeCaching = require('next-pwa/cache')
module.exports = withPWA({
pwa: {
dest: 'public',
register: true,
runtimeCaching,
}
})
这里是manifest.json
{
"name": "nex-pwa",
"short_name": "app",
"display": "fullscreen",
"orientation": "portrait",
"theme_color": "#3056de",
"background_color": "#3056de",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "/icons/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "/icons/homescreen48.png",
"sizes": "48x48",
"type": "image/png"
}, {
"src": "/icons/homescreen72.png",
"sizes": "72x72",
"type": "image/png"
}, {
"src": "/icons/homescreen96.png",
"sizes": "96x96",
"type": "image/png"
}, {
"src": "/icons/homescreen144.png",
"sizes": "144x144",
"type": "image/png"
}
],
"splash_pages": null
}
还有 Nginx server 文件
server
{
root /var/www/domain.com/html/pwa;
server_name domain.com www.domain.com;
error_log /var/www/domain.com/html/pwa/log/error.log;
location ~/images(.*$) {
proxy_pass http://localhost:3035/images$1;
proxy_redirect off;
}
location ~/fonts(.*$) {
proxy_pass http://localhost:3035/fonts$1;
proxy_redirect off;
}
location ~/icons(.*$) {
proxy_pass http://localhost:3035/icons$1;
proxy_redirect off;
}
location ~/sw.js(.*$) {
proxy_pass http://localhost:3035/sw.js$1;
proxy_redirect off;
}
location ~/workbox-c2b5e142.js(.*$) {
proxy_pass http://localhost:3035/workbox-c2b5e142.js$1;
proxy_redirect off;
}
location ~/_next(.*)$ {
proxy_pass http://localhost:3035/_next$1;
proxy_redirect off;
}
location / {
proxy_pass http://localhost:3035;
proxy_redirect off;
}
location ~ /\.ht {
deny all;
}
}
它正在本地开发服务器上进行开发,但是当我使用 nginx 部署到 DigitalOcean 之类的生产环境时,它不再工作了,我的意思是 Web 应用程序工作但浏览器上没有显示安装图标。
我做错了什么,拜托。
谢谢
【问题讨论】:
-
不应该是
manifest.json吗? -
@JaromandaX 是的!这是一个打字错误。
-
不知你的nginx配置是否正确
-
任何网络错误?您的 sw.js 文件是否存在并提供服务?
-
@felixmosh 是的,它在浏览器控制台中显示错误,但网络工作正常。
workbox-c2b5e142.js:1 Uncaught (in promise) bad-precaching-response: bad-precaching-response :: [{"url":"https://domain/css/animate.min.css","status":404}] at P (https:/domain/workbox-c2b5e142.js:1:11329) at async Promise.all (index 0) at async P.install (https://domain/workbox-c2b5e142.js:1:10742)
标签: javascript reactjs nginx next.js progressive-web-apps