-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
83 lines (58 loc) · 2.7 KB
/
server.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
require('dotenv').config()
// require("dotenv-safe").config();
// require('@tvgloborecursosartisticos/joi-ptbr')
require('./utils/pt_br')
const AWS = require('aws-sdk')
const awilix = require('awilix')
const init = async () => {
// const DB_CONFIG_Pool_MYSQL = {
// "connectionLimit": 10,
// "port": 3306,
// "host": "localhost",
// "user": "root",
// "password": "adm1234",
// "database": "estudo",
// "autocommit": 0
// }
const DB_CONFIG_MYSQL_JSON =
{
"host": "localhost",
"user": "root",
"password": "adm1234",
"database": "estudo"
}
// SSM - instancia
const ssm = new AWS.SSM()
// SSM - DB
const ssmParams = { Name: DB_CONFIG_MYSQL_JSON, WithDecryption: true }
const dbPoolConnectionConfig = DB_CONFIG_MYSQL_JSON ? DB_CONFIG_MYSQL_JSON : JSON.parse((await ssm.getParameter(ssmParams).promise()).Parameter.Value)
// const ssmParams = { Name: process.env.DB_CONFIG_MYSQL_JSON , WithDecryption: true }
// const dbPoolConnectionConfig = process.env.DB_CONFIG_MYSQL_JSON ? JSON.parse(process.env.DB_CONFIG_MYSQL_JSON ) : JSON.parse((await ssm.getParameter(ssmParams).promise()).Parameter.Value)
const container = awilix.createContainer()
container.register({
moment: awilix.asValue(require('moment')) ,
mysqldb: awilix.asValue(require('mysql')) ,
joi: awilix.asValue(require('joi')),
expressValidator: awilix.asValue(require('express-joi-validation').createValidator({})),
apicache: awilix.asValue(require('apicache')),
dbPoolConnectionConfig: awilix.asValue(dbPoolConnectionConfig),
dbConnectionPoolClient: awilix.asClass(require('./utils/db/mysql-db-connection-pool')).singleton(),
alunoDomain: awilix.asClass(require('./domain/aluno-domain')).scoped(),
alunoController: awilix.asFunction(require('./adapters/aluno-rest-api').Controller).scoped(),
alunoRoute: awilix.asFunction(require('./adapters/aluno-rest-api').Route).scoped(),
alunoSchema: awilix.asFunction(require('./adapters/aluno-rest-api').Schema).singleton(),
alunoDb: awilix.asClass(require('./adapters/aluno-db-adapter')).singleton(),
})
// WEBSERVER
const Webserver = require('./webserver-component/webserver-component')
new Webserver(process.env.SERVER_PORT, {
initialPluginList: [
// [require('./adapters/scope-interceptor')({ container })]
],
finalPluginList: [ ],
routeList: [
container.resolve('alunoRoute')
]
}).init()
}
init()