Skip to content

Commit e67ca10

Browse files
author
rinaldo stevenazzi
committed
add services mongodb, user. add global controller and server
1 parent fe24b57 commit e67ca10

File tree

8 files changed

+1774
-1
lines changed

8 files changed

+1774
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ yarn-error.log
1010

1111

1212
#ide
13-
.idea
13+
.idea
14+
15+
#env
16+
.env

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: npm start

controllers/Global.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const MongoDB = require("../Services/MongoDB")
2+
const Users = require("../services/Users");
3+
4+
class Global {
5+
constructor(){
6+
console.log('Global Class Constructor')
7+
this.mongoDB = new MongoDB()
8+
this.users = new Users()
9+
this.db = {}
10+
11+
this.initDB = this.initDB.bind(this)
12+
}
13+
14+
initDB () {
15+
return new Promise((resolve, reject) => {
16+
this.mongoDB.getDB()
17+
.then(result => {
18+
this.db = result
19+
console.log('Global Controller - initDB initialisation', this.db)
20+
this.users.init(this.db)
21+
resolve(null)
22+
})
23+
.catch(e => {
24+
console.log('Global Controller - initDB initialisation failed !!!')
25+
reject(e)
26+
})
27+
})
28+
}
29+
}
30+
31+
module.exports = Global

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const express = require('express');
2+
const http = require('http')
3+
require('dotenv').config()
4+
const Global = require('./Controllers/Global')
5+
6+
const app = express()
7+
const server = http.createServer(app)
8+
const PORT = process.env.API_PORT
9+
10+
console.log('process env', process.env)
11+
12+
const globalController = new Global()
13+
globalController.initDB()
14+
.then(() => console.log('SERVER - initDB - DONE'))
15+
.catch((e) => console.log('SERVER - initDB - ERROR', e))
16+
17+
app.use(express.json())
18+
app.get('/', async (req, res) => {
19+
res.send('<h1>Hello world</h1>')
20+
});
21+
22+
23+
server.listen(PORT, () => {
24+
console.log(`Listening on ${ PORT }`)
25+
})

0 commit comments

Comments
 (0)