Update pattern

This commit is contained in:
Secven 2021-06-30 20:35:37 +00:00
parent ea75918c43
commit e606922e47
8 changed files with 28 additions and 7 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
logs
.idea/
.DS_Store
.tmp
*.log
npm-debug.log*
yarn-debug.log*

View File

@ -0,0 +1,13 @@
# pattern-rest-api
* Test to request
* Use api test to - https://github.com/Kong/insomnia
> POST http://127.0.0.1:5050/v1/token
>
> {
"name": "AlphaServer",
"token": "d41d8cd98f00b204e9800998ecf8427e"
}
>

View File

@ -16,7 +16,6 @@ class App extends Incs {
if (autoScale) worker = this.autoScale(worker)
if (cluster.isMaster) {
winInfo('****** Cluster Master Online ******')
for (let i = 0; i < worker; i += 1) {
winInfo(`****** Creating instances [ ${worker} ] ******`)
cluster.fork()

View File

@ -34,7 +34,7 @@ class HubColl {
return [
check('token', 'Token len: min 10 or 30 max').isLength({
min: 10,
max: 30
max: 32
})
]
}

View File

@ -2,6 +2,8 @@ const ms = require('ms')
const config = {}
config.isDev = process.env.NODE_ENV === 'development'
config.rateLimitOpts = {
windowMs: ms('5m'),
max: process.env.RATELIMIT_MAX,

View File

@ -13,8 +13,11 @@ const { config } = require('../config/config')
const app = express()
app.use(rateLimit(config.rateLimitOpts))
app.use(Waf.WafMiddleware(wafrules.DefaultSettings))
if (!config.isDev) {
app.use(rateLimit(config.rateLimitOpts))
app.use(Waf.WafMiddleware(wafrules.DefaultSettings))
}
app.use(boyParser.json())
app.use(boyParser.urlencoded({ extended: false }))
app.use(morgan('dev'))

View File

@ -1,6 +1,6 @@
const CS = require('chalk')
const mongoose = require('mongoose')
const { winErr } = require('./util/logger')
const { config } = require('./config/config')
class Incs {
buildMongoose = async () => {
@ -20,11 +20,11 @@ class Incs {
)
.catch(err => console.error(CS.red(`Error mongoose: ${err.message}`)))
mongoose.set('debug', true)
mongoose.set('debug', config.isDev)
process.on('SIGINT', () => {
mongoose.connection.close(() => {
winErr('Close connection mongoose')
console.info(CS.red('Close connection mongoose'))
process.exit(0)
})
})

2
test/test.js Normal file
View File

@ -0,0 +1,2 @@
const len = 'd41d8cd98f00b204e9800998ecf8427e'
console.log(len.length)