-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
84 lines (69 loc) · 2.5 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const express = require("express");
const app = express();
const swaggerUi = require("swagger-ui-express"),
swaggerDocument = require("./swagger.json");
const mongoose = require("mongoose");
const expenses = require("./routes/expenses");
const users = require("./routes/users");
const auth = require("./routes/auth");
const friends = require("./routes/friends");
const repayments = require("./routes/repayments");
const notification_tokens = require("./routes/notification_tokens");
const categories = require("./routes/categories");
const admin = require("firebase-admin");
// const cors = require("cors");
const config = require("config");
if (!config.get("jwtPrivateKey")) {
console.error("FATAL ERROR: jwtPrivateKey not defined");
process.exit(1);
}
if (!config.get("database")) {
console.error("FATAL ERROR: database not defined");
process.exit(1);
}
if (!config.get("MJ_APIKEY_PUBLIC")) {
console.error("FATAL ERROR: MJ_APIKEY_PUBLIC not defined");
process.exit(1);
}
if (!config.get("MJ_APIKEY_PRIVATE")) {
console.error("FATAL ERROR: MJ_APIKEY_PRIVATE not defined");
process.exit(1);
}
if (!config.get("GOOGLE_APPLICATION_CREDENTIALS")) {
console.error("FATAL ERROR: GOOGLE_APPLICATION_CREDENTIALS not defined");
process.exit(1);
}
if (!config.get("firebase_database")) {
console.error("FATAL ERROR: firebase_database not defined");
process.exit(1);
}
mongoose
.connect(config.get("database"))
.then(() => console.log("Connected to mongodb"))
.catch((err) => console.log("Could not connect to mongodb...", err));
//Startups
const serviceAccount = JSON.parse(
Buffer.from(config.get("GOOGLE_APPLICATION_CREDENTIALS"), "base64").toString(
"ascii"
)
);
const firebaseDatabaseUrl = config.get("firebase_database");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: firebaseDatabaseUrl,
});
console.log("Initialized Firebase SDK");
// app.use(cors({ origin: ["http://127.0.0.1:3000", "http://localhost:3000"] }));
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use(express.json());
app.use("/api/users", users);
app.use("/api/auth", auth);
app.use("/api/expenses", expenses);
app.use("/api/friends", friends);
app.use("/api/repayments", repayments);
app.use("/api/repayments", repayments);
app.use("/api/notification_tokens", notification_tokens);
app.use("/api/categories", categories);
const port = process.env.PORT || 3500;
app.listen(port, () => console.log(`Listening on port ${port}...`));
module.exports.customAdmin = admin;