脚本宝典收集整理的这篇文章主要介绍了Firebase - a ready-made backend system,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
DEMO:git clone https://github.com/rhildred/firebasetodo.git
open firebase:https://console.firebase.google.com/
- create new project
- realtime database: change its rule to public
- project setting: find the config, and then paste to firebase.js
apiKey: "AIzaSyCbgXrV1bbY_nJ1GwwYeFqYlOO0dzxNSDQ", authDomain: "test1-89c24.firebaseapp.com", projectId: "test1-89c24", storageBucket: "test1-89c24.appspot.com", messagingSenderId: "845740612813", appId: "1:845740612813:web:a0c094ef21a40a8d749d84", measurementId: "G-00V4RGNLYE"
- Linux command: npx http-server
(node js app ( npx http-server ) is an HTTP server itself and it serves your static files to the browser.)
- Effect:
port 8080 is like:
at the same time, in firebase realtime database:
DEMO: git clone https://github.com/rhildred/twiliobot2021.git
3.1 add files under static folder
firebase.js
export default { apiKey: "AIzaSyCbgXrV1bbY_nJ1GwwYeFqYlOO0dzxNSDQ", authDomain: "test1-89c24.firebaseapp.com", projectId: "test1-89c24", storageBucket: "test1-89c24.appspot.com", messagingSenderId: "845740612813", appId: "1:845740612813:web:a0c094ef21a40a8d749d84", measurementId: "G-00V4RGNLYE" };
order.js
import "https://cdnjs.cloudflare.com/ajax/libs/firebase/7.24.0/firebase-app.js"; import "https://cdnjs.cloudflare.com/ajax/libs/firebase/7.24.0/firebase-database.js" // Your web app's Firebase configuration import firebaseConfig from "./firebase.js"; // Initialize Firebase firebase.initializeApp(firebaseConfig); window.fireorder = (order)=>{ const todoID = new Date().toISOString().replace(".", "_"); firebase.database().ref('orders/' + todoID).set(order).then(() => { alert('Order saved.'); window.open("", "_self"); window.close(); }).catch(e => { console.log(e.toString()); }); }
3.2 ShawarmaOrder.js
add <script src="/js/order.js" type="module"></script> at line 87, so it will affect payal website
line 104 when transaction succeed, invoke firebase function to save details.
$.post(".", details, ()=>{
window.fireorder(details);
});
以上是脚本宝典为你收集整理的Firebase - a ready-made backend system全部内容,希望文章能够帮你解决Firebase - a ready-made backend system所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。