-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (50 loc) · 1.62 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
56
57
58
59
require('dotenv').config();
const functions = require('firebase-functions/v2');
const admin = require('firebase-admin');
const express = require('express');
const cors = require('cors');
const { urlencoded, json } = require('body-parser');
const app = express();
const serviceAccount = require('./i-am-human.json');
const SupabaseRouter = require('./router/supabase');
const Is_Admin = require('./router/is_admin');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
app.use(urlencoded({ extended: true }));
app.use(express.json({ extended: true }));
app.use(json());
app.use(cors({ origin: true }));
app.use(express.json({ limit: '100mb' }));
app.use(express.urlencoded({ limit: '100mb' }));
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header(
'Access-Control-Allow-Methods',
'GET, POST, OPTIONS, PUT, PATCH, DELETE'
);
res.header(
'Access-Control-Allow-Headers',
'x-access-token, Origin, X-Requested-With, Content-Type, Accept'
);
const allowedHosts = [
'https://i-am-human.app/',
'https://i-am-human-dev.netlify.app/',
'https://i-am-human-dev.netlify.app',
'https://i-am-human.app',
];
if (allowedHosts.includes(req.headers.origin)) {
next();
} else {
res.send('Access Denied');
}
});
app.use(SupabaseRouter);
app.use(Is_Admin);
const port = process.env.PORT || 3001;
app.listen(port, () => {
console.log('app running on port ' + port);
});
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
// exports.dev = functions.https.onRequest(app);