This file contains hidden or 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
const mongoose = require('mongoose'); | |
const connectMongo = (mongoURI) => { | |
mongoose.connect(mongoURI, { useNewUrlParser: true }); | |
mongoose.connection.on('error', (err) => { | |
console.log(err); | |
process.exit(); | |
}); | |
}; |
This file contains hidden or 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
const { getUsersCtrl } = require('../controllers/userController') | |
module.exports = async function (fastify) { | |
fastify.get('/users', getUsersCtrl) | |
} |
This file contains hidden or 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
const { getUsers } = require('../adaptors/userAdaptor'); | |
const getUsersCtrl = async (req, res) => { | |
try { | |
const { page } = req.query; | |
const users = await getUsers({ page }); | |
res.send(users); | |
} | |
catch (err) { | |
throw err; |
This file contains hidden or 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
const nconf =require('nconf'); | |
const joinUrl = require('url-join'); | |
const { getRequest } = require('../utils/httpClient'); | |
const usersAPIUrl = nconf.get('url.usersAPI'); | |
const getUsers = ({page = 1}) => getRequest({ | |
url: joinUrl(usersAPIUrl, 'users', `?page=${page}`) | |
}) |
This file contains hidden or 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
const request = require('request-promise-native'); | |
const nconf = require('nconf'); | |
const externalAPITimeout = nconf.get('app.externalAPITimeout'); | |
const getRequest = ({url, options}) => request.get(url, {...options, timeout: externalAPITimeout, json:true}); | |
module.exports = { | |
getRequest | |
} |
This file contains hidden or 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
{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"type": "node", | |
"request": "launch", | |
"name": "Launch Program", |
This file contains hidden or 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
// import dependencies from npm | |
const Fastify = require('fastify'); | |
const path = require('path'); | |
const AutoLoad = require('fastify-autoload'); | |
const uuidv4 = require('uuid/v4'); | |
// create request ids | |
const createRequestId = () => uuidv4(); | |
const createServer = (options) => { |
This file contains hidden or 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
// api/routes/root.js | |
module.exports = async function (fastify, opts) { | |
fastify.get('/', async function (request, reply) { | |
return { hello: "World" } | |
}) | |
} |
This file contains hidden or 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
{ | |
"logSeverity": "info", | |
"app": { | |
"isEmailVerificationEnabled": false, | |
"emailTokenExpiryInSeconds": "7d", | |
"userPasswordRegex" : "^(?=.{6,})", | |
"userJwtExpiry" : "2d" | |
}, | |
"url" : { | |
"self": "", |
This file contains hidden or 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
// import dependencies from npm | |
const Fastify = require('fastify'); | |
const path = require('path'); | |
const AutoLoad = require('fastify-autoload'); | |
const uuidv4 = require('uuid/v4'); | |
// create request ids | |
const createRequestId = () => uuidv4(); | |
const createServer = (options) => { |