-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
64 lines (53 loc) · 1.9 KB
/
Copy pathserver.js
File metadata and controls
64 lines (53 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require('dotenv').config();
const express = require('express');
const path = require('path');
const Firebase = require('firebase');
const every = require('every-moment');
const firebaseApiKey = process.env.firebaseApiKey;
const serverEmail = process.env.FIREBASE_SERVER_EMAIL;
const serverPassword = process.env.FIREBASE_SERVER_PASSWORD;
const firebaseConfig = {
apiKey: firebaseApiKey,
authDomain: 'kongtrackr.firebaseapp.com',
databaseURL: 'https://kongtrackr.firebaseio.com',
projectId: 'kongtrackr',
storageBucket: 'kongtrackr.appspot.com',
messagingSenderId: '262693445312',
appId: '1:262693445312:web:b731292d66cdecfa'
};
const fbApp = Firebase.initializeApp(firebaseConfig);
var kongtrackr = require('./server/batch');
// var algoliaIndices = require('./server/algoliaUpdate');
const app = express();
// Serve only the static files from the dist directory
app.use(express.static(__dirname + '/dist/apps/kongtrackr'));
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/apps/kongtrackr/index.html'));
});
app.listen(process.env.PORT || 8080);
console.log(`Kongtrackr server started on ${process.env.PORT || 8080}.`);
// Function to start batch operations
function startBatchOperations() {
kongtrackr.runBatch();
// algoliaIndices.watchData();
// Batch schedule
var timer = every(30, 'minutes', function() {
kongtrackr.runBatch();
});
}
// Authenticate server as a regular user.
if (serverEmail && serverPassword) {
Firebase.auth()
.signInWithEmailAndPassword(serverEmail, serverPassword)
.then(() => {
console.log('Server authenticated with Firebase');
startBatchOperations();
})
.catch(error => {
console.error('Server authentication failed:', error);
// Don't start batch operations if auth fails
});
} else {
// If no credentials, start batch operations anyway (for backward compatibility)
startBatchOperations();
}