Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

angular - FCM service worker not working in production

When running the production build in localhost, the fcm is working properly, but when i run it in my aws ec2 instance i got the following error :

Unhandled Promise rejection: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('https://mydomain/firebase-cloud-messaging-push-scope') with script ('https://mydomain/firebase-messaging-sw.js'): The script has an unsupported MIME type ('text/html'). (messaging/failed-service-worker-registration). ; Zone: ; Task: Promise.then ; Value: FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('https://mydomain/firebase-cloud-messaging-push-scope') with script ('https://mydomain/firebase-messaging-sw.js'): The script has an unsupported MIME type ('text/html'). (messaging/failed-service-worker-registration).

I have put the firebase-messaging-sw.js file in the root folder, also set mime type in httpd.conf file but the error still persists. I looked into similiar problems in SO but mostly they use react while i'm using angular. Please help me fix this issue, thank you

question from:https://stackoverflow.com/questions/65650025/fcm-service-worker-not-working-in-production

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It turn out that my apache configuration causing all js file treated as 'text/html'.

In /etc/httpd/conf.d/php.conf there is this line

AddType application/x-httpd-php .html .php .xml .js

i changed it to AddType application/x-httpd-php .html .php .xml

restarting httpd and the service worker registered successfully.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...