-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (30 loc) · 1.19 KB
/
Copy pathserver.js
File metadata and controls
34 lines (30 loc) · 1.19 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
const app = require("./app");
const mongoose = require("mongoose");
const { initializeBackgroundJobs } = require("./lib/background-jobs");
const PORT = process.env.PORT || 3000;
const mongoosePort = process.env.MONGODB_PORT || 27017;
try {
// will create database if it can't see one
// martin doesn't expose mongodb outside of the web server; you'd never want to make that available
// otherwise people could brute force attack
// even if you tried to do this, the server would probably complain
// you probably dont want to tinker the live db, just the local db (e.g. modify a model file)
mongoose
.connect(`mongodb://localhost:${mongoosePort}/komondor`, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 10000, // 10 seconds
})
.then(() => {
console.log("Connected to MongoDB");
// Initialize background jobs after DB connection is established
initializeBackgroundJobs();
})
.catch((err) => {
console.error("Error connecting to MongoDB", err);
});
} catch (err) {
console.error("Unexpected error:", err);
}
app.listen(PORT, () => console.log(`API running on port ${PORT}!`));