**I am trying to update the data using firestore, it works fine on the phone and run web but it does not work when I do a build and upload file to my server -- index.html >> **
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.9.3/firebase-app.js";
import { getFirestore, collection, getDocs } from 'https://www.gstatic.com/firebasejs/9.9.3/firebase-firestore.js';
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: -----,
authDomain: ------,
projectId: ------,
storageBucket: ------,
messagingSenderId: ------,
appId: ------,
measurementId: ------
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
</script>
update firestore code>>
FirebaseFirestore.instance
.collection('orderDetails')
.doc(id)
.update({
'status': status,
}).catchError((e) {
print(e);
});
and get this error in browser console
Refused to load the script 'https://www.gstatic.com/firebasejs/9.9.3/firebase-app.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval' http://myserverurl.com https://myserverurl.com http://www.myserverurl.com https://www.myserverurl.com". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
also this error
VM86:3 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: https://www.gstatic.com/firebasejs/9.9.0/firebase-app.js
CodePudding user response:
Update your index.html in folder web to this :
<script src="https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.17.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.4.1/firebase-messaging.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/8.6.5/firebase-analytics.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=yourKey"></script>
<script>
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: -----,
authDomain: ------,
projectId: ------,
storageBucket: ------,
messagingSenderId: ------,
appId: ------,
measurementId: ------
};
/// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
and on your server Edit your file .htaccess if you use set Header set Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://example.com remove it