-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adds logging capabilities * replaces restify with fastify * removes main restify server * renames var * removes deprecated dependencies * removes deprecated next middleware function * removes restify errors * config eslint * decouple server from app * refactors integration tests * fixes static file serving * removes TODO
- Loading branch information
Showing
18 changed files
with
1,461 additions
and
1,695 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ DB_HOST=localhost | |
DB_PORT=27017 | ||
DB_DATABASE=users | ||
DB_USER=myuser | ||
DB_PASS=mypass | ||
DB_PASS=mypass | ||
|
||
LOG_LEVEL=info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2021": true, | ||
"mocha": true | ||
}, | ||
"extends": [ | ||
"standard" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 12 | ||
}, | ||
"rules": { | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": "*.test.js", | ||
"rules": { | ||
"no-unused-expressions": "off" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
require('dotenv').config() | ||
require('make-promises-safe') | ||
|
||
const container = require('./infrastructure/config/container')() | ||
const server = require('./infrastructure/webserver/server') | ||
const server = require('./infrastructure/webserver/fastify')(container.cradle) | ||
|
||
module.exports = server(container.cradle) | ||
server.listen(3000, (err, address) => { | ||
if (err) { | ||
server.log.error(err) | ||
process.exit(1) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,18 @@ | ||
const { createContainer, asFunction } = require('awilix') | ||
const { createContainer } = require('awilix') | ||
const resolveLogger = require('./logger') | ||
const resolveDB = require('./database') | ||
|
||
const container = createContainer() | ||
|
||
const resolveDB = ({ DB_DRIVER, NODE_ENV }) => { | ||
if (NODE_ENV === 'test') DB_DRIVER = 'in-memory' | ||
|
||
if (DB_DRIVER === 'in-memory') inMemoryDB() | ||
else if (DB_DRIVER === 'mongo') mongoDB() | ||
} | ||
|
||
const inMemoryDB = () => { | ||
const UserRepositoryInMemory = require('../repositories/UserRepositoryInMemory') | ||
|
||
container.register({ | ||
UserRepository: asFunction(UserRepositoryInMemory).singleton() | ||
}) | ||
} | ||
|
||
const mongoDB = () => { | ||
const UserRepositoryMongo = require('../repositories/UserRepositoryMongo') | ||
|
||
// Load Database and Schemas | ||
container.loadModules([ | ||
'infrastructure/database/**/*.js' | ||
]) | ||
|
||
container.register({ | ||
UserRepository: asFunction(UserRepositoryMongo) | ||
}) | ||
} | ||
|
||
module.exports = () => { | ||
container.loadModules([ | ||
'ports/**/*.js', | ||
'application/**/*.js', | ||
'domain/**/*.js' | ||
]) | ||
|
||
resolveDB(process.env) | ||
resolveDB(container) | ||
resolveLogger(container) | ||
|
||
return container | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { asFunction } = require('awilix') | ||
|
||
const inMemoryDB = container => { | ||
const UserRepositoryInMemory = require('../repositories/UserRepositoryInMemory') | ||
|
||
container.register({ | ||
UserRepository: asFunction(UserRepositoryInMemory).singleton() | ||
}) | ||
} | ||
|
||
const mongoDB = container => { | ||
const UserRepositoryMongo = require('../repositories/UserRepositoryMongo') | ||
|
||
// Load Database and Schemas | ||
container.loadModules([ | ||
'infrastructure/database/**/*.js' | ||
]) | ||
|
||
container.register({ | ||
UserRepository: asFunction(UserRepositoryMongo) | ||
}) | ||
} | ||
|
||
const resolveDB = container => { | ||
if (process.env.NODE_ENV === 'test') process.env.DB_DRIVER = 'in-memory' | ||
|
||
if (process.env.DB_DRIVER === 'in-memory') inMemoryDB(container) | ||
else if (process.env.DB_DRIVER === 'mongo') mongoDB(container) | ||
} | ||
|
||
module.exports = resolveDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { asValue } = require('awilix') | ||
|
||
const resolveLogger = container => { | ||
const isDev = process.env.NODE_ENV === 'development' | ||
const config = { | ||
name: 'app', | ||
prettyPrint: isDev, | ||
level: process.env.LOG_LEVEL || 'info' | ||
} | ||
|
||
const Logger = require('pino')(config) | ||
|
||
container.register({ | ||
Logger: asValue(Logger) | ||
}) | ||
|
||
container.register({ | ||
LoggerConfig: asValue(config) | ||
}) | ||
} | ||
|
||
module.exports = resolveLogger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.