-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (26 loc) · 816 Bytes
/
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
const express = require("express");
const knex = require("knex");
const { Model } = require("objection");
const dbConfig = require("./knexfile");
const { initRoutes } = require("./src/routes/routes");
const { startStatsListeners } = require("./src/events/events");
const { logger } = require("./src/logger/logger");
const db = knex(dbConfig.development);
Model.knex(db);
const app = express();
app.use(express.json());
app.use(logger);
initRoutes(app);
const port = 4066;
const server = app.listen(port, async () => {
try {
await db.raw('select 1+1 as result')
console.log('Connected to db');
startStatsListeners();
console.log(`App listening at http://localhost:${port}`);
} catch {
console.error('No db connection');
}
});
// Do not change this line
module.exports = { app, server };