Merge pull request #98 from christroutner/unstable

Updating dependencies & MongoDB
This commit is contained in:
Chris Troutner
2021-02-04 17:29:57 -08:00
committed by GitHub
13 changed files with 19722 additions and 1912 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2016 Adrian Obelmejias <adrian@obel.me> & Chris Troutner <chris.troutner@gmail.com>
Copyright (c) 2021 Chris Troutner <chris.troutner@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-6
View File
@@ -1,6 +0,0 @@
#!/bin/bash
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo service mongod start
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo service mongod start
sudo systemctl enable mongod
+19616 -1827
View File
File diff suppressed because it is too large Load Diff
+26 -26
View File
@@ -31,43 +31,43 @@
},
"repository": "christroutner/koa-api-boilerplate",
"dependencies": {
"apidoc": "^0.23.0",
"axios": "^0.21.1",
"bcryptjs": "^2.4.3",
"glob": "^7.0.0",
"jsonwebtoken": "^8.3.0",
"kcors": "^2.2.1",
"koa": "^2.5.0",
"koa-bodyparser": "^4.2.0",
"koa-convert": "^1.2.0",
"koa-generic-session": "^2.0.1",
"koa-logger": "^3.1.0",
"glob": "^7.1.6",
"jsonwebtoken": "^8.5.1",
"kcors": "^2.2.2",
"koa": "^2.13.1",
"koa-bodyparser": "^4.3.0",
"koa-convert": "^2.0.0",
"koa-generic-session": "^2.1.1",
"koa-logger": "^3.2.1",
"koa-mount": "^4.0.0",
"koa-passport": "^4.1.3",
"koa-router": "^9.0.1",
"koa-router": "^10.0.0",
"koa-static": "^5.0.0",
"line-reader": "^0.4.0",
"mongoose": "^5.10.15",
"nodemailer": "^6.4.10",
"mongoose": "^5.11.15",
"nodemailer": "^6.4.17",
"passport-local": "^1.0.0",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^4.0.0"
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.0"
},
"devDependencies": {
"chai": "^4.1.2",
"coveralls": "^3.0.2",
"eslint": "5.16.0",
"eslint-config-prettier": "^6.0.0",
"eslint-config-standard": "^14.1.0",
"apidoc": "^0.26.0",
"chai": "^4.3.0",
"coveralls": "^3.1.0",
"eslint": "7.19.0",
"eslint-config-prettier": "^7.2.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-standard": "^4.0.0",
"husky": "^4.2.5",
"mocha": "^7.0.1",
"nyc": "^15.0.0",
"semantic-release": "^17.2.3",
"sinon": "^9.2.1",
"standard": "^14.3.1"
"husky": "^4.3.8",
"mocha": "^8.2.1",
"nyc": "^15.1.0",
"semantic-release": "^17.3.7",
"sinon": "^9.2.4",
"standard": "^16.0.3"
},
"release": {
"publish": [
+14 -8
View File
@@ -18,7 +18,7 @@ const JsonFiles = require('./utils/json-files')
const jsonFiles = new JsonFiles()
const JSON_FILE = `system-user-${config.env}.json`
const JSON_PATH = `${__dirname}/../../config/${JSON_FILE}`
const JSON_PATH = `${__dirname.toString()}/../../config/${JSON_FILE}`
const LOCALHOST = `http://localhost:${config.port}`
const context = {}
@@ -39,7 +39,7 @@ class Admin {
// used by the Listing Manager and test scripts, in order access private API
// functions.
async createSystemUser () {
// Create the system user.
// Create the system user.
try {
context.password = _this._randomString(20)
@@ -81,13 +81,15 @@ class Admin {
// Handle existing system user.
if (err.response.status === 422) {
try {
// Delete the existing user
// Delete the existing user
await _this.deleteExistingSystemUser()
// Call this function again.
return _this.createSystemUser()
} catch (err2) {
console.error('Error in admin.js/createSystemUser() while trying generate new system user.')
console.error(
'Error in admin.js/createSystemUser() while trying generate new system user.'
)
// process.end(1)
throw err2
}
@@ -104,7 +106,10 @@ class Admin {
mongoose.Promise = global.Promise
mongoose.set('useCreateIndex', true) // Stop deprecation warning.
await mongoose.connect(config.database, { useNewUrlParser: true, useUnifiedTopology: true })
await mongoose.connect(config.database, {
useNewUrlParser: true,
useUnifiedTopology: true
})
await _this.User.deleteOne({ email: 'system@system.com' })
} catch (err) {
@@ -147,9 +152,10 @@ class Admin {
}
_randomString (length) {
var text = ''
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
for (var i = 0; i < length; i++) {
let text = ''
const possible =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
for (let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length))
}
return text
+3 -3
View File
@@ -12,8 +12,8 @@ require('winston-daily-rotate-file')
const config = require('../../config')
// Configure daily-rotation transport.
var transport = new winston.transports.DailyRotateFile({
filename: `${__dirname}/../../logs/koa-${config.env}-%DATE%.log`,
const transport = new winston.transports.DailyRotateFile({
filename: `${__dirname.toString()}/../../logs/koa-${config.env}-%DATE%.log`,
datePattern: 'YYYY-MM-DD',
zippedArchive: false,
maxSize: '1m', // 1 megabyte
@@ -29,7 +29,7 @@ transport.on('rotate', function (oldFilename, newFilename) {
})
// This controls what goes into the log FILES
var wlogger = winston.createLogger({
const wlogger = winston.createLogger({
level: 'verbose',
format: winston.format.json(),
transports: [
+3 -3
View File
@@ -126,9 +126,9 @@ class Validators {
if (ctx.state.user._id.toString() !== targetId.toString()) {
wlogger.verbose(
`Calling user and target user do not match! Calling user: ${
ctx.state.user._id
}, Target user: ${targetId}`
`Calling user and target user do not match! Calling user: ${
ctx.state.user._id
}, Target user: ${targetId}`
)
// If they don't match, then the calling user better be an admin.
+42 -34
View File
@@ -2,46 +2,54 @@ const glob = require('glob')
const Router = require('koa-router')
module.exports = function initModules (app) {
glob(`${__dirname}/*`, { ignore: '**/index.js' }, (err, matches) => {
if (err) { throw err }
glob(
`${__dirname.toString()}/*`,
{ ignore: '**/index.js' },
(err, matches) => {
if (err) {
throw err
}
// Loop through each sub-directory in the modules directory.
matches.forEach((mod) => {
// console.log(`router = ${mod}/router`)
const router = require(`${mod}/router`)
// Loop through each sub-directory in the modules directory.
matches.forEach((mod) => {
// console.log(`router = ${mod}/router`)
const router = require(`${mod}/router`)
const routes = router.routes
const baseUrl = router.baseUrl
const instance = new Router({ prefix: baseUrl })
const routes = router.routes
const baseUrl = router.baseUrl
const instance = new Router({ prefix: baseUrl })
// console.log(`routes: ${JSON.stringify(routes, null, 2)}`)
// console.log(`routes: ${JSON.stringify(routes, null, 2)}`)
// Loop through each route defined in the router.js file.
routes.forEach((config) => {
// console.log(`modules/index.js config: ${JSON.stringify(config, null, 2)}`)
// const {
// method = '',
// route = '',
// handlers = []
// } = config
const method = config.method || ''
const route = config.route || ''
const handlers = config.handlers || []
// Loop through each route defined in the router.js file.
routes.forEach((config) => {
// console.log(`modules/index.js config: ${JSON.stringify(config, null, 2)}`)
// const {
// method = '',
// route = '',
// handlers = []
// } = config
const method = config.method || ''
const route = config.route || ''
const handlers = config.handlers || []
const lastHandler = handlers.pop()
const lastHandler = handlers.pop()
instance[method.toLowerCase()](route, ...handlers, async function (ctx) {
// console.log(`typeof lastHandler: ${typeof (lastHandler)}`)
// return await lastHandler(ctx)
return lastHandler(ctx)
instance[method.toLowerCase()](
route,
...handlers,
async function (ctx) {
// console.log(`typeof lastHandler: ${typeof (lastHandler)}`)
// return await lastHandler(ctx)
return lastHandler(ctx)
}
)
// console.log(`instance: ${JSON.stringify(instance, null, 2)}`)
app.use(instance.routes()).use(instance.allowedMethods())
})
// console.log(`instance: ${JSON.stringify(instance, null, 2)}`)
app
.use(instance.routes())
.use(instance.allowedMethods())
})
})
})
}
)
}
+1 -1
View File
@@ -149,7 +149,7 @@ class LogsApi {
_this.config.env
}-${thisYear}-${thisMonth}-${thisDate}.log`
// console.log(`filename: ${filename}`)
const logDir = `${__dirname}/../../../logs/`
const logDir = `${__dirname.toString()}/../../../logs/`
const fullPath = `${logDir}${filename}`
// console.log(`fullPath: ${fullPath}`)
+1 -1
View File
@@ -8,7 +8,7 @@ util.inspect.defaultOptions = { depth: 1 }
const JsonFiles = require('../../src/lib/utils/json-files')
const JSON_FILE = 'test-json-file.json'
const JSON_PATH = `${__dirname}/${JSON_FILE}`
const JSON_PATH = `${__dirname.toString()}/${JSON_FILE}`
const deleteFile = filepath => {
try {
+4 -1
View File
@@ -9,7 +9,10 @@ async function addUser () {
// Connect to the Mongo Database.
mongoose.Promise = global.Promise
mongoose.set('useCreateIndex', true) // Stop deprecation warning.
await mongoose.connect(config.database, { useNewUrlParser: true })
await mongoose.connect(
config.database,
{ useNewUrlParser: true, useUnifiedTopology: true }
)
const User = require('../../src/models/users')
+4 -1
View File
@@ -8,7 +8,10 @@ async function getUsers () {
// Connect to the Mongo Database.
mongoose.Promise = global.Promise
mongoose.set('useCreateIndex', true) // Stop deprecation warning.
await mongoose.connect(config.database, { useNewUrlParser: true })
await mongoose.connect(
config.database,
{ useNewUrlParser: true, useUnifiedTopology: true }
)
const users = await User.find({}, '-password')
console.log(`users: ${JSON.stringify(users, null, 2)}`)