-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mike Bieser
committed
May 16, 2016
0 parents
commit 8f8ad68
Showing
27 changed files
with
333 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"node": true, | ||
"es5": true, | ||
"esnext": true, | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"indent": 2, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"quotmark": "single", | ||
"regexp": true, | ||
"undef": true, | ||
"unused": true, | ||
"strict": true, | ||
"trailing": true, | ||
"smarttabs": true, | ||
"white": true | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
> The place to record changes made in each new version. | ||
#### 0.0.1 - May 16, 2016 | ||
- API generated. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM docker-hub.8-network.com/node:4.2.2 | ||
|
||
MAINTAINER Demandforce <[email protected]> | ||
|
||
#Want docker to cache node_modules, unless there is a change to package.json | ||
ADD package.json /tmp/package.json | ||
RUN cd /tmp && npm config set strict-ssl false && npm install | ||
|
||
WORKDIR /d3-usr/src/app | ||
|
||
RUN mkdir -p /usr/src/app/log && cp -ar /tmp/node_modules /d3-usr/src/app/node_modules | ||
|
||
ADD . /d3-usr/src/app | ||
|
||
CMD npm start |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
var express = require('express'); | ||
var path = require('path'); | ||
require("coffee-script/register") | ||
var favicon = require('serve-favicon'); | ||
var logger = require('morgan'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
var v1Routes = require('./routes/v1'); | ||
var admin = require('./routes/admin'); | ||
|
||
var app = express(); | ||
|
||
var env = process.env.NODE_ENV || 'development'; | ||
app.locals.ENV = env; | ||
app.locals.ENV_DEVELOPMENT = env == 'development'; | ||
|
||
// app.use(favicon(__dirname + '/public/img/favicon.ico')); | ||
app.use(logger(env)); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ | ||
extended: true | ||
})); | ||
app.use(cookieParser()); | ||
|
||
app.use('/v1', v1Routes); | ||
app.use('/', v1Routes); | ||
app.use('/admin', admin); | ||
|
||
|
||
/// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
var err = new Error('Not Found'); | ||
err.status = 404; | ||
next(err); | ||
}); | ||
|
||
/// error handler | ||
|
||
// development error handler | ||
// will print stacktrace | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
if (app.get('env') === 'development') { | ||
res.send(err.message) | ||
} else { | ||
res.end(); | ||
} | ||
|
||
|
||
}); | ||
|
||
|
||
module.exports = app; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
# To be used in CI deploy steps | ||
set -e |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
# To be used in CI publish steps | ||
set -e | ||
|
||
echo DOCKER_REGISTRY_HOST=${DOCKER_REGISTRY_HOST} | ||
echo PROJECT_NAME=${PROJECT_NAME} | ||
echo SHA=$SHA | ||
echo ${DOCKER_REGISTRY_HOST}/${PROJECT_NAME}:$SHA | ||
echo "" | ||
|
||
docker build -t ${DOCKER_REGISTRY_HOST}/${PROJECT_NAME}:$SHA . | ||
docker push ${DOCKER_REGISTRY_HOST}/${PROJECT_NAME}:$SHA | ||
|
||
docker build -t ${DOCKER_REGISTRY_HOST}/${PROJECT_NAME}:production . | ||
docker push ${DOCKER_REGISTRY_HOST}/${PROJECT_NAME}:production | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
# To be used in CI build steps | ||
set -e | ||
sleep 20 | ||
docker-compose run -T app npm test |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
# To be used in CI build steps | ||
set -e | ||
|
||
docker pull docker-hub.8-network.com/node | ||
|
||
docker-compose stop && \ | ||
docker-compose rm --force | ||
|
||
docker-compose build |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
# To be used in CI build steps | ||
set -e | ||
docker-compose kill | ||
docker-compose rm --force |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env node | ||
var app = require('../app'); | ||
|
||
app.set('port', process.env.PORT || 3000); | ||
|
||
var server = app.listen(app.get('port'), function() { | ||
console.log('Express server listening on port ' + server.address().port); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
app: | ||
build: . | ||
command: npm start | ||
ports: | ||
- "3000:3000" | ||
volumes: | ||
- ./:/dev-d3-usr |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
var db = require("../utils/db-connection") | ||
|
||
function getBusinessById(id, callback){ | ||
let GET_BUSINESS = "SELECT ID as id, NAME as name, STATUS as status FROM Business WHERE ID = ?" | ||
db.query({businessId:id}, GET_BUSINESS, [id], function(err, results){ | ||
if(err) { | ||
callback(err) | ||
} else { | ||
callback(null, results[0]) | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
getBusinessById: getBusinessById | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var PORTAL_URL, config, log, request, url; | ||
request = require('request'); | ||
config = require('../config/env.json')[process.env.NODE_ENV]; | ||
url = require("url"); | ||
log = require('../config/logger').mainLogger; | ||
|
||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | ||
process.env.NODE_ENV = process.env.NODE_ENV || "development"; | ||
|
||
PORTAL_URL = config.portal.url; | ||
|
||
module.exports = function(cookie) { | ||
var options; | ||
options = { | ||
url: PORTAL_URL + "/bp2/session.jsp", | ||
headers: { | ||
cookie: "JSESSIONID=" + req.cookies.JSESSIONID | ||
}, | ||
followRedirect: false | ||
}; | ||
return request(options, function(error, response, body) { | ||
var url_parts; | ||
if (error) { | ||
return res.status(500).end(); | ||
} | ||
if (response.statusCode === 200) { | ||
req.business = JSON.parse(body).business; | ||
return next(); | ||
} else if (response.statusCode === 301 || response.statusCode === 302) { | ||
url_parts = url.parse(response.headers.location); | ||
log.error({ | ||
err: { | ||
response: response.statusCode, | ||
cookie: req.cookies, | ||
sessionID: req.cookies.JSESSIONID, | ||
url_parts: url_parts | ||
} | ||
}, 'session 300'); | ||
res.redirect("/bp2/secureRedirect.jsp?redirectUrl=/portal/settings/scheduling"); | ||
} else { | ||
return res.status(500).end(); | ||
} | ||
}); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "foo2", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"start": "node_modules/.bin/forever -w ./bin/www" | ||
}, | ||
"dependencies": { | ||
"body-parser": "^1.13.3", | ||
"bunyan": "^1.7.1", | ||
"coffee-script": "^1.10.0", | ||
"cookie-parser": "^1.3.3", | ||
"d3-database": "1.0.4", | ||
"express": "^4.13.3", | ||
"forever": "^0.15.1", | ||
"morgan": "^1.6.1", | ||
"serve-favicon": "^2.3.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "2.4.5" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var business = require("../lib/business") | ||
|
||
function getBusinessId(req, res, next){ | ||
business.getBusinessById(req.params["businessId"], function(err, business){ | ||
if(err) { | ||
console.log(err.message) | ||
next(err) | ||
} else if(business==null) { | ||
next(new Error("Business not found")) | ||
} else { | ||
res.send(business) | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { | ||
getBusinessId: getBusinessId | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET health */ | ||
router.get('/health', function(req, res) { | ||
res.send('OK'); | ||
}); | ||
|
||
module.exports = router; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module.exports = require("v1") | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET health */ | ||
router.get('/health', function(req, res) { | ||
res.send('OK'); | ||
}); | ||
|
||
module.exports = router; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
var businessHandler = require("../../routeHandlers/businessHandler") | ||
|
||
router.get('/:businessId', function(req, res, next) { | ||
businessHandler.getBusinessById(req, res, next); | ||
}); | ||
|
||
router.get("/", function(req, res){ | ||
res.send("Hello Business World!"); | ||
}) | ||
|
||
module.exports = router; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
var businessRoutes = require("./business") | ||
|
||
router.get('/', function(req, res) { | ||
res.send("Hello World!") | ||
}); | ||
|
||
router.use('/business', businessRoutes) | ||
|
||
module.exports = router; |
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var logger = require("./logger"); | ||
var POOLSIZE = 10; | ||
var routes = require("d3-database").routes; | ||
var connection = require("d3-database").connection(routes[process.env.NODE_ENV || "development"], POOLSIZE, logger); | ||
|
||
module.exports = { | ||
nodegroups: connection.nodegroups, | ||
query: connection.query, | ||
ping: connection.ping | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var LOG_LEVEL, Logger, configs; | ||
|
||
Logger = require('bunyan'); | ||
|
||
if (process.env.DEBUG) { | ||
LOG_LEVEL = 'debug'; | ||
} | ||
|
||
configs = { | ||
name: process.env.NODE_PROCESS_NAME || 'business-api', | ||
streams: [ | ||
{ | ||
stream: process.stdout, | ||
level: LOG_LEVEL || 'info' | ||
} | ||
] | ||
}; | ||
|
||
module.exports = new Logger(configs); |