Implement Firebase emulator

This commit is contained in:
Conor McNamara
2023-02-22 21:20:26 +00:00
parent f42f58deb9
commit f837780e10
13 changed files with 1549 additions and 701 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
dist/favicon.ico vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

4
dist/index.html vendored
View File

@ -5,8 +5,8 @@
<link rel="icon" href="/favicon.ico"> <link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Irish Rail Tracker</title> <title>Irish Rail Tracker</title>
<script type="module" crossorigin src="/assets/index-383d0d29.js"></script> <script type="module" crossorigin src="/assets/index-f45376ca.js"></script>
<link rel="stylesheet" href="/assets/index-9a76eada.css"> <link rel="stylesheet" href="/assets/index-24f118f5.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -18,5 +18,20 @@
"firebase-debug.*.log" "firebase-debug.*.log"
] ]
} }
] ],
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 5002
},
"hosting": {
"port": 5000
},
"ui": {
"enabled": true
},
"singleProjectMode": true
}
} }

View File

@ -18,7 +18,7 @@ exports.getLiveTrainData = functions.https.onRequest((request, response) => {
// fetch the "liveTrainData" collection // fetch the "liveTrainData" collection
admin.firestore().collection('liveTrainData').get().then((snapshot) => { admin.firestore().collection('liveTrainData').get().then((snapshot) => {
if (snapshot.empty) { if (snapshot.empty) {
response.send("Error fetching data from the database"); response.send({data: "Error fetching data from the database"});
return; return;
} }
// iterate through each of the collection's documents // iterate through each of the collection's documents

View File

@ -9,7 +9,8 @@
"axios": "^1.3.3", "axios": "^1.3.3",
"firebase": "^9.17.1", "firebase": "^9.17.1",
"firebase-admin": "^11.5.0", "firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.0" "firebase-functions": "^4.2.0",
"xml2js": "^0.4.23"
}, },
"devDependencies": { "devDependencies": {
"firebase-functions-test": "^3.0.0" "firebase-functions-test": "^3.0.0"
@ -6051,6 +6052,11 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
}, },
"node_modules/sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"node_modules/semver": { "node_modules/semver": {
"version": "6.3.0", "version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
@ -6718,6 +6724,26 @@
"node": "^12.13.0 || ^14.15.0 || >=16.0.0" "node": "^12.13.0 || ^14.15.0 || >=16.0.0"
} }
}, },
"node_modules/xml2js": {
"version": "0.4.23",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",
"integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==",
"dependencies": {
"sax": ">=0.6.0",
"xmlbuilder": "~11.0.0"
},
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/xmlbuilder": {
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==",
"engines": {
"node": ">=4.0"
}
},
"node_modules/xmlcreate": { "node_modules/xmlcreate": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.4.tgz", "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.4.tgz",

View File

@ -16,7 +16,8 @@
"axios": "^1.3.3", "axios": "^1.3.3",
"firebase": "^9.17.1", "firebase": "^9.17.1",
"firebase-admin": "^11.5.0", "firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.0" "firebase-functions": "^4.2.0",
"xml2js": "^0.4.23"
}, },
"devDependencies": { "devDependencies": {
"firebase-functions-test": "^3.0.0" "firebase-functions-test": "^3.0.0"

949
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,7 @@
}, },
"dependencies": { "dependencies": {
"axios": "^1.3.1", "axios": "^1.3.1",
"firebase": "^9.17.1",
"ol": "^7.2.2", "ol": "^7.2.2",
"vue": "^3.2.45", "vue": "^3.2.45",
"vue-loading-overlay": "^6.0.3", "vue-loading-overlay": "^6.0.3",

View File

@ -44,7 +44,7 @@
import { ref } from 'vue'; import { ref } from 'vue';
import {fromLonLat, toLonLat} from 'ol/proj.js'; import {fromLonLat, toLonLat} from 'ol/proj.js';
import app from '../api/firebase'; import app from '../api/firebase';
import { getFunctions, httpsCallable } from "firebase/functions"; import { getFunctions, httpsCallable, connectFunctionsEmulator } from "firebase/functions";
export default { export default {
name: "MapsOverlay", name: "MapsOverlay",
@ -77,7 +77,8 @@ export default {
}, },
created() { created() {
// initial request of fata // initial request of data
console.log("jere")
this.getLiveTrainData() this.getLiveTrainData()
// request new data every 60 seconds // request new data every 60 seconds
@ -88,8 +89,10 @@ export default {
// fetch live train data from the Firestore database // fetch live train data from the Firestore database
getLiveTrainData() { getLiveTrainData() {
const functions = getFunctions(app); const functions = getFunctions(app);
if (window.location.hostname === '127.0.0.1') {
connectFunctionsEmulator(functions, "localhost", 5001);
}
const getData = httpsCallable(functions, 'getLiveTrainData'); const getData = httpsCallable(functions, 'getLiveTrainData');
let loader = this.$loading.show({ let loader = this.$loading.show({
loader: 'dots', loader: 'dots',
container: this.$refs.container, container: this.$refs.container,
@ -97,14 +100,18 @@ export default {
}); });
getData().then((response) => { getData().then((response) => {
try {
this.dbLiveTrainData = response.data; this.dbLiveTrainData = response.data;
// create an array of coordinates and hashmap with the key-values {index: JSON obj} // create an array of coordinates and hashmap with the key-values {index: JSON obj}
for(var i=0; i<this.dbLiveTrainData.length; i++) { for(var i=0; i<this.dbLiveTrainData.length; i++) {
this.coordinates[i] = ref(fromLonLat([this.dbLiveTrainData[i]["TrainLongitude"][0], this.dbLiveTrainData[i]["TrainLatitude"][0]])) this.coordinates[i] = ref(fromLonLat([this.dbLiveTrainData[i]["TrainLongitude"][0], this.dbLiveTrainData[i]["TrainLatitude"][0]]))
this.allDataMap[i] = this.dbLiveTrainData[i]; this.allDataMap[i] = this.dbLiveTrainData[i];
} }
loader.hide(); loader.hide();
}
catch (error) {
loader.hide();
}
}) })
}, },
@ -123,6 +130,9 @@ export default {
// ---------------- TESTING ---------------- // ---------------- TESTING ----------------
postLiveTrainData() { postLiveTrainData() {
const functions = getFunctions(app); const functions = getFunctions(app);
if (window.location.hostname === '127.0.0.1') {
connectFunctionsEmulator(functions, "localhost", 5001);
}
const postData = httpsCallable(functions, 'postLiveTrainData'); const postData = httpsCallable(functions, 'postLiveTrainData');
postData().then((response) => { postData().then((response) => {