-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (47 loc) · 1.36 KB
/
index.js
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
const functions = require('firebase-functions');
const express = require('express');
const cors = require('cors');
var admin = require("firebase-admin");
const { getAuth } = require('firebase-admin/auth');
var serviceAccount = require("./config.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://vochafunding-default-rtdb.firebaseio.com"
});
const app = express();
app.use(cors())
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
app.get('/', (req, res) => {
const date = new Date();
const hours = (date.getHours() % 12) + 1; // London is UTC + 1hr;
res.send(`
<!doctype html>
<head>
<title>Time</title>
<link rel="stylesheet" href="/style.css">
<script src="/script.js"></script>
</head>
<body>
<p>In London, the clock strikes:
<span id="bongs">${'BONG '.repeat(hours)}</span></p>
<button onClick="refresh(this)">Refresh</button>
</body>
</html>`);
});
app.get('/auth', (req, res) => {
var idToken = req.body.idToken;
getAuth()
.verifyIdToken(idToken)
.then((decodedToken) => {
const uid = decodedToken.uid;
res.send(uid)
})
.catch((error) => {
// Handle error
});
});
exports.app = functions.https.onRequest(app);