Firebase messaging in production - javascript

I have a project that works with FCM. On the localhost, every thing works fine and I get the token for FCM; but, in production, I get this error:
FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('https://myxdomain.com/firebase-cloud-messaging-push-scope') with script ('https://myxdomain/firebase-messaging-sw.js'): A bad HTTP response code (403) was received when fetching the script. (messaging/failed-service-worker-registration).
I'm deploying my app in an Apache server.

As mentioned here, you need to add firebase-messaging-sw.js file in correct folder. It may be something like this: /var/www/...

Related

Netlify throws 404 error with /graphql only when deployed

I have an app which I had pushed to heroku a few days ago, where it works fine, but when deploying the app to Netlify, the app deploys but the graphQL connection throws a 404 error. Here are some images.
Here is the code I use in App.js
Is there anyone that knows how I can fix this? Much appreciated
Netlify doesn't run a app server like Heroku, it only runs a static file server. From your code, it appears that you're trying to serve a app that you could connect to and provide yourself with GraphQL access. This is not possible on Netlify, at least not directly.
The only server-like solution that Netlify currently provides in Netlify Functions. However, those are limited to 10 sec by default and provide, one-time data connection - not something that you could keep on using for GraphQL.
So if your requirement is to keep the GraphQL server running (for example like what Gatsby does during gatsby develop), Netlify is not the solution for you. If you wish to send the data one-time and add some server-side processing, you can take a look at Netlify Functions.

Failed to register service-worker TypeError - Expo Error

I have recently encountered the following error when I npm run start my expo app;
Uncaught DOMException: Failed to execute 'importScripts' on
'WorkerGlobalScope': The script at
'http://localhost:19006/service-worker.js' failed to load.
at http://localhost:19006/expo-service-worker.js:93:6
The script has an unsupported MIME type ('text/html').
This error has never occurred until of late, in which I pulled down the app source code onto a new machine, so I have a incline that this could be the issue.
When I used to Service Worker debugger using Chrome Dev Tools, the error flags up on the last line of the code in expo-service-worker.js (see screenshot)
I have literally done nothing different, I have seen other solutions stating I should modify some of the service-worker registration code, but this sits uncomfortable with me being as this is an automatic process when running the app.
The app boots-up fine, but it has trouble connecting to the external api linked to the app, because the service worker is not being registered.
One my other machine, the app launches, registers a service worker and connects to the api fine, just not on the machine currently.
Any suggestions?
Thanks.
A service worker importScripts() script must be served with a valid javascript content-type header. See:
https://w3c.github.io/ServiceWorker/#dfn-bad-import-script-response
In this case you are getting a content-type of text/html. One common way this can happen is if the server returns a 404 for the resource URL passed to importScripts.

Registering Serviceworker in Laravel

I'm using pushpad (from pushpad.xyz) and followed the 3 initial steps to setup this SDK with my Laravel 5.5 Project.
But as soon as I visit a test view it just cannot find and register the Serviceworker.js
i tried placing it all over the place, almost in every folder now. So i know this is vaguely described but if you take a quick look at the Docs from pushpad you know what I mean.
Moreover, when i manually try to open it i get a 404.
also getting 404 when i try to import it via from the https:// link where its located
when i copy its content and use it in a script tag i also get a 404.
im quite clueless as how to proceed
A bad HTTP response code (404) was received when fetching the script.
Failed to load resource: net::ERR_INVALID_RESPONSE
push-test:1 Uncaught (in promise) TypeError: Failed to register a
ServiceWorker: A bad HTTP response code (404) was received when fetching the
script.
You need to make sure that you have a service-worker.js file in the root directory of your website.
You can verify the installation by typing https://example.com/service-worker.js in your browser.

Vue Js register/update a ServiceWorker error

I trying to implement Firebase Push Notification into Vue Js and after doing watching this video https://www.youtube.com/watch?v=XdzXaW8IbBM I tried to implement it, but after writing below code in firebase-messaging-sw.js it is giving me error on service worker. Both I have provided below.
Code firebase-messaging-sw.js
importScripts('/__/firebase/3.8.0/firebase-app.js');
importScripts('/__/firebase/3.8.0/firebase-messaging.js');
importScripts('/__/firebase/init.js');
firebase.messaging();
Error
Failed to register/update a ServiceWorker for scope ‘http://localhost:3000/firebase-cloud-messaging-push-scope’: Bad Content-Type of ‘text/html’ received for script ‘http://localhost:3000/firebase-messaging-sw.js’. Must be ‘text/javascript’, ‘application/x-javascript’, or ‘application/javascript’.
2nd Error
FirebaseError: Messaging: We are unable to register the default service worker.
The operation is insecure. (messaging/failed-serviceworker-registration).
Note: My application is on Vue Js + Nuxt Js
When I am trying to get the token on console I am getting below output.
Promise { <state>: "pending" }

Heroku reCaptcha in node.js app

I'm trying to integrate reCaptcha to my node'js app. When I run the app locally everything's fine. But when I deploy the app to heroku, reCaptcha prints an error and is blocked for usage. If I open the console in browser I see Failed to load resource: the server responded with a status of 400 (Bad Request) from https://google.com/...
I guess that heroku blocks something, but just googling it didn't help.
Thanks for your support.
Without more information, it seems most likely that the domain of your Heroku app is not listed in your reCAPTCHA account, or your site-key is not set correctly.

Categories