Skip to content

Commit

Permalink
Updated to kth-node-configuration@1.3.1 = DOCKER READY + simplified s…
Browse files Browse the repository at this point in the history
…ettings
  • Loading branch information
jhsware committed Jan 24, 2017
1 parent fdcffe9 commit ccb509a
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 128 deletions.
6 changes: 0 additions & 6 deletions config/commonSettings.js

This file was deleted.

2 changes: 0 additions & 2 deletions config/devSettings.js

This file was deleted.

34 changes: 0 additions & 34 deletions config/localSettings.js.in

This file was deleted.

1 change: 0 additions & 1 deletion config/prodSettings.js

This file was deleted.

1 change: 0 additions & 1 deletion config/refSettings.js

This file was deleted.

29 changes: 0 additions & 29 deletions config/secretSettings.js

This file was deleted.

52 changes: 52 additions & 0 deletions config/serverSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
*
* Server specific settings
*
* *************************************************
* * WARNING! Secrets should be read from env-vars *
* *************************************************
*
*/
const { getEnv, unpackMongodbConfig } = require('kth-node-configuration')
const { safeGet } = require('safe-utils')

// DEFAULT SETTINGS used for dev, if you want to override these for you local environment, use env-vars in .env
const devPrefixPath = '/api/node'
const devSsl = false
const devPort = 3001
const devMongodb = 'mongodb://localhost:27017/node'
// END DEFAULT SETTINGS

module.exports = {
// The proxy prefix path if the application is proxied. E.g /places
proxyPrefixPath: {
uri: getEnv('SERVICE_PUBLISH', devPrefixPath)
},
useSsl: safeGet(() => getEnv('SERVER_SSL', devSsl + '').toLowerCase() == 'true'),
port: getEnv('SERVER_PORT', devPort),

ssl: {
// In development we don't have SSL feature enabled
pfx: getEnv('SERVER_CERT_FILE', ''),
passphrase: getEnv('SERVER_CERT_PASSPHRASE', '')
},

// API keys
api_keys: [{
name: 'devClient',
apikey: getEnv('NODE_API_KEY', '1234'),
scope: ['write', 'read']
}],

// Services
db: unpackMongodbConfig('MONGODB_URI', devMongodb),

// Logging
logging: {
log: {
level: getEnv('LOGGING_LEVEL', 'debug')
}
}

// Custom app settings
}
27 changes: 7 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
{
"//": "The production flag is added in the jenkins build script.",
"name": "node-api",
"version": "1.0.0",
"version": "2.0.0",
"description": "Node.js based API template application.",
"main": "app.js",
"private": true,
"scripts": {
"test": "tape \"test/**/*.js\" | tap-spec",
"test:coverage": "istanbul cover tape -- \"test/**/*.js\"",
"codecheck": "standard",
"codefix": "standard --fix",
"preversion": "npm run codecheck && npm run test",
"postversion": "git push && git push --tags",
"nodeInspector": "node-inspector --web-port 8890",
"openDebugBrowser": "sleep 2s && open http://127.0.0.1:8890/\\?port\\=5858 &2>/dev/null",
"installAndStart": "npm install && npm start",
"start": "cross-env NODE_ENV=development nodemon app.js",
"startDebug": "node --debug-brk app.js",
"startMock": "NODE_MOCK=1 npm start",
"debug": "cross-env NODE_ENV=development concurrently --kill-others \"npm run startDebug\" \"npm run nodeInspector\" \"npm run openDebugBrowser\""
"test": "echo \"ok\"",
"start": "cross-env NODE_ENV=development nodemon app.js"
},
"dependencies": {
"bluebird": "^3.4.6",
"body-parser": "^1.15.2",
"co": "^4.6.0",
"component-registry": "^0.2.0",
"cookie-parser": "^1.4.3",
"dotenv": "^4.0.0",
"express": "^4.14.0",
"express-handlebars": "^3.0.0",
"kth-node-access-log": "KTH/kth-node-access-log.git#v1.0.0",
"kth-node-api-key-strategy": "KTH/kth-node-api-key-strategy.git#v1.0.2",
"kth-node-configuration": "KTH/kth-node-configuration.git#v1.0.1",
"kth-node-configuration": "KTH/kth-node-configuration.git#v1.3.1",
"kth-node-log": "KTH/kth-node-log.git#v1.0.1",
"kth-node-mongo": "KTH/kth-node-mongo.git#v1.0.3",
"kth-node-monitor": "https://github.com/KTH/kth-node-monitor.git#v0.1.2",
Expand All @@ -45,16 +35,13 @@
"concurrently": "^2.2.0",
"cross-env": "^2.0.0",
"istanbul": "^0.4.4",
"nodemon": "^1.10.0",
"proxyquire": "^1.7.10",
"standard": "^7.1.2",
"tap-spec": "^4.1.1",
"tape": "^4.6.0"
},
"optionalDependencies": {
"node-inspector": "^0.12.8",
"nodemon": "^1.10.0"
},
"engines": {
"node": "4.3.1"
"node": "6.9.1"
}
}
2 changes: 1 addition & 1 deletion server/controllers/systemCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const packageFile = require('../../package.json')
const config = require('../init/configuration').full
const config = require('../init/configuration').server
const paths = require('../init/routing/paths')
const db = require('kth-node-mongo')

Expand Down
4 changes: 2 additions & 2 deletions server/init/authentication/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'

const log = require('kth-node-log')
const config = require('../configuration')
const config = require('../configuration').server
const passport = require('passport')
const server = require('../../server')
const apiKey = require('kth-node-api-key-strategy')

const ApiKeyStrategy = apiKey.Strategy
const options = { log: log }
const verify = (req, apikey, done) => {
apiKey.verifyApiKey(req, apikey, config.secure.api_keys, done)
apiKey.verifyApiKey(req, apikey, config.api_keys, done)
}
const strategy = new ApiKeyStrategy(options, verify)

Expand Down
21 changes: 6 additions & 15 deletions server/init/configuration/configuration.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
'use strict'
const { generateConfig } = require('kth-node-configuration')

const configurator = require('kth-node-configuration')
// These settings are used by the server
const serverConfig = generateConfig([
require('../../../config/serverSettings')
])

const config = configurator({
defaults: require('../../../config/commonSettings'),
local: require('../../../config/localSettings'),
ref: require('../../../config/refSettings'),
prod: require('../../../config/prodSettings'),
dev: require('../../../config/devSettings')
})

module.exports = {
full: config.full(),
secure: config.secure(),
safe: config.safe(),
env: config.env()
}
module.exports.server = serverConfig
12 changes: 6 additions & 6 deletions server/init/database/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict'

const config = require('../configuration')
const config = require('../configuration').server
const log = require('kth-node-log')
const nodeMongo = require('kth-node-mongo')

const mongoOptions = {
user: config.secure.db.username,
pass: config.secure.db.password,
user: config.db.username,
pass: config.db.password,
server: {
authenticationDatabase: config.secure.db.authDatabase,
ssl: config.secure.db.ssl
authenticationDatabase: config.db.authDatabase,
ssl: config.db.ssl
},
maxPoolSize: 5,
dbUri: config.secure.db.uri,
dbUri: config.db.uri,
logger: log
}

Expand Down
4 changes: 2 additions & 2 deletions server/init/logging/logging.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

const log = require('kth-node-log')
const config = require('../configuration')
const config = require('../configuration').server
const packageFile = require('../../../package.json')
const path = require('path')
const fs = require('fs')

const configuration = config.full.logging
const configuration = config.logging
const environment = config.env

let logConfiguration = {
Expand Down
2 changes: 1 addition & 1 deletion server/init/middleware/accessLog.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const accessLog = require('kth-node-access-log')
const config = require('../configuration').full
const config = require('../configuration').server
const server = require('../../server')

server.use(accessLog(config.logging.accessLog))
2 changes: 1 addition & 1 deletion server/lib/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const log = require('kth-node-log')
const server = require('../server')
const passport = require('passport')
const proxyPrefixPath = require('../init/configuration').full.proxyPrefixPath.uri
const proxyPrefixPath = require('../init/configuration').server.proxyPrefixPath.uri
const url = require('url')

module.exports = {
Expand Down
14 changes: 7 additions & 7 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict'

const server = require('kth-node-server')
const config = require('./init/configuration')
const config = require('./init/configuration').server
const log = require('kth-node-log')

server.start({
pfx: config.full.ssl.pfx,
passphrase: config.full.ssl.passphrase,
key: config.full.ssl.key,
ca: config.full.ssl.ca,
cert: config.full.ssl.cert,
port: config.full.port,
pfx: config.ssl.pfx,
passphrase: config.ssl.passphrase,
key: config.ssl.key,
ca: config.ssl.ca,
cert: config.ssl.cert,
port: config.port,
log
})

Expand Down

0 comments on commit ccb509a

Please sign in to comment.