-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
68 lines (57 loc) · 2.02 KB
/
app.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
60
61
62
63
64
65
66
67
68
// Modules
const cors = require('cors');
const compression = require('compression');
const helmet = require('helmet');
const cookieParser = require('cookie-parser');
const express = require('express');
const logger = require('morgan');
const path = require('path');
// Routes
const bibleRouter = require('./routes/bible');
// const indexRouter = require('./routes/index');
const { usersRouter, usersFirebaseInit } = require('./routes/users');
const { socialRouter, socialFirebaseInit } = require('./routes/social');
const { notesRouter, notesFirebaseInit } = require('./routes/notes')
// Firebase imports
const firebase = require('firebase');
const admin = require("firebase-admin");
const { applicationDefault } = require("firebase-admin/app");
const { firebaseConfig } = require('./routes/firebaseConf');
// Firebase setup
const firebaseApp = admin.initializeApp({
credential: applicationDefault(),
databaseURL: 'https://basil-backend-47d01-default-rtdb.firebaseio.com/'
});
const db = admin.database();
firebase.initializeApp(firebaseConfig);
usersFirebaseInit(firebase, firebaseApp, db);
socialFirebaseInit(firebase, firebaseApp, db);
notesFirebaseInit(firebase, firebaseApp, db);
// App
const app = express();
const port = process.env.PORT || 3000;
app.use(helmet()); // For security policy
app.use(cors()); // For Cross-Origin Resource Sharing
app.use(compression()); // For bandwidth saving on the more intensive actions
// view engine setup
/*
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.set('caseSensitive', true);
*/
// Express setup
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// Routes usage
app.use('/api', bibleRouter);
app.use('/', usersRouter, socialRouter, notesRouter);
app.get('/health', (req, res) => {
res.status(200).send("Healthy: OK");
})
app.listen(port, () => {
console.log(`API server listening on port ${port}`);
});
module.exports = app;