Skip to content

Commit

Permalink
create a skeleton on Express
Browse files Browse the repository at this point in the history
  • Loading branch information
ZIMkaRU committed May 28, 2018
1 parent c5a132d commit 22a1a6c
Show file tree
Hide file tree
Showing 28 changed files with 5,892 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"env": {
"commonjs": true,
"mocha": true,
"node": true,
"es6": true
},
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"classes": true,
"defaultParameters": true,
"destructuring": true,
"forOf": true,
"generators": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"regexUFlag": true,
"regexYFlag": true,
"restParams": true,
"spread": true,
"superInFunctions": true,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"globalReturn": true
},
"globals": {
"_": false,
"angular": false,
"mocks": false,
"console": false,
"inject": true,
"module": true,
"window": false,
"expect": true,
"require": true,
"onPrepare": true,
"onComplete": true,
"browser": true,
"jasmine": true,
"sinon": true,
"beforeEach": true,
"afterEach": true,
"schema": true
}
}
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea/
.vscode/
node_modules/
public/jspm_packages/
public/node_modules/
public/bower/
config/local-production.yaml
config/local-development.yaml
config/local-test.yaml
logs/*
!logs/.gitkeep
3 changes: 3 additions & 0 deletions .mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require test/helpers
--recursive test/**/*.spec.js
--timeout 10000
62 changes: 62 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict'

if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production'

const express = require('express')
const app = express()
const config = require('config')
const morgan = require('morgan')
const methodOverride = require('method-override')
const bodyParser = require('body-parser')

module.exports = { app }

const { headersMiddleware } = require('./src/middlewares')
const { corsService, logDebugService, logService } = require('./src/services')
const responses = require('./src/services/helpers/responses')
const { logger } = logService

const routes = require('./src/routes')

const port = config.get('app.port')
const host = config.get('app.host')

app.use(corsService.corsBase())
app.use(headersMiddleware)
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(methodOverride())

if (
config.has('logDebug.enableServerStream') &&
config.get('logDebug.enableServerStream')
) {
app.use(
morgan('combined', {
stream: { write: msg => logDebugService.debug(msg) }
})
)
}

app.use('/', routes)

app.use((req, res, next) => {
responses.failure(404, 'Not found', res)
})

app.use((err, req, res, next) => {
logger.error('Found %s at %s', 'error', err)

responses.failure(
err.statusCode ? err.statusCode : 500,
err.message || err.statusMessage || '',
res
)
})

const server = app.listen(port, host, function() {
const host = server.address().address
const port = server.address().port

logger.info(`Server listening on host ${host} port ${port}`)
})
27 changes: 27 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
app:
port: 31339
host: 127.0.0.1
cors:
enable: true
whitelist: null # array

logDebug:
prefix: ''
postfix: :app
enableInfo: true
enableDev: true
enableError: true
enableServerStream: true

log:
label: :app
pathError: logs/error.log
pathExcLogger: logs/exceptions-logger.log
pathLog: logs/log.log
enableConsole: true
enableColor: true
enableColorPathError: false
enableColorPathExcLogger: false
enableColorPathLog: false
maxSize: null

14 changes: 14 additions & 0 deletions config/development.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
app:
port: 31339
host: 127.0.0.1

logDebug:
postfix: :app-dev
enableInfo: true
enableDev: true
enableError: true
enableServerStream: true

log:
label: :app-dev
pathExcLogger: null
5 changes: 5 additions & 0 deletions config/local-development.yaml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
app:
port: 31339
cors:
enable: true
whitelist: null # array
10 changes: 10 additions & 0 deletions config/local-production.yaml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
app:
port: 31339
cors:
enable: true
whitelist: null # array

log:
label: :app-prod
pathError: logs/error.log
pathExcLogger: 'logs/exceptions-logger.log'
13 changes: 13 additions & 0 deletions config/local-test.yaml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
app:
port: 3001

logDebug:
postfix: :app-test
enableInfo: false
enableDev: false
enableError: false
enableServerStream: false

log:
label: :app-test
enableConsole: false
16 changes: 16 additions & 0 deletions config/production.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
app:
port: 31339
host: 127.0.0.1

logDebug:
postfix: :app-prod
enableInfo: false
enableDev: false
enableError: false
enableServerStream: false

log:
label: :app-prod
enableConsole: false
pathError: null
pathLog: null
14 changes: 14 additions & 0 deletions config/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
app:
port: 3001
host: 127.0.0.1

logDebug:
postfix: :app-test
enableInfo: false
enableDev: false
enableError: false
enableServerStream: false

log:
label: :app-test
enableConsole: false
Empty file added logs/.gitkeep
Empty file.
Loading

0 comments on commit 22a1a6c

Please sign in to comment.