diff --git a/.gitignore b/.gitignore index 59d842baa8..33cbfe4df7 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,7 @@ node_modules # Users Environment Variables .lock-wscript + +# Idea stuff +.idea +*.iml diff --git a/.jshintrc b/.jshintrc index 1f54ec4fe0..3c6252a265 100644 --- a/.jshintrc +++ b/.jshintrc @@ -11,7 +11,6 @@ "after" : false, "beforeEach": false, "afterEach" : false, - "assert" : false, "contain" : false }, diff --git a/unleash-server/README.md b/unleash-server/README.md index 936e069b90..4ddbf3ab43 100644 --- a/unleash-server/README.md +++ b/unleash-server/README.md @@ -1,2 +1,20 @@ # unleash-server unleash-server is a place to ask for the status of features. + + +# Important commands: + +``` +//Start server in dev-mode: +npm run start-dev + +//Admin dashboard +http://localhost:4242 + +//Feature API: +http://localhost:4242/features + + +//Execute tests: +npm test +``` \ No newline at end of file diff --git a/unleash-server/lib/api.js b/unleash-server/lib/api.js new file mode 100644 index 0000000000..336643d8cd --- /dev/null +++ b/unleash-server/lib/api.js @@ -0,0 +1,5 @@ +module.exports = function (app) { + app.get('/features', function (req, res) { + res.send('some nice json features here!'); + }); +}; \ No newline at end of file diff --git a/unleash-server/lib/logger.js b/unleash-server/lib/logger.js new file mode 100644 index 0000000000..60b8a2bece --- /dev/null +++ b/unleash-server/lib/logger.js @@ -0,0 +1,6 @@ +var log4js = require('log4js'); + +log4js.clearAppenders(); +log4js.addAppender(log4js.appenders.console()); + +module.exports = log4js.getLogger('unleash'); \ No newline at end of file diff --git a/unleash-server/lib/routes.js b/unleash-server/lib/routes.js new file mode 100644 index 0000000000..a7d89154a7 --- /dev/null +++ b/unleash-server/lib/routes.js @@ -0,0 +1,7 @@ +module.exports = function (app) { + + app.get('/health', function (req, res) { + res.json({health: 'GOOD'}); + }); + +}; \ No newline at end of file diff --git a/unleash-server/package.json b/unleash-server/package.json new file mode 100644 index 0000000000..16ec2d7b5d --- /dev/null +++ b/unleash-server/package.json @@ -0,0 +1,43 @@ +{ + "name": "unleash-server", + "description": "unleash your features", + "version": "0.0.1", + "keywords": [ + "unleash", + "feature toggle", + "feature", + "toggle" + ], + "repository": { + "type": "git", + "url": "ssh://git@github.com:finn-no/unleash.git" + }, + "bugs": { + "url": "https://github.com/finn-no/unleash/issues" + }, + "private": true, + "scripts": { + "start": "node server.js", + "start-dev": "NODE_ENV=local supervisor --ignore ./node_modules/ server.js", + "test": "jshint server.js lib public/scripts test && mocha test test/*", + "tdd": "mocha --watch test test/*", + "test-bamboo-ci": "mocha test test/*" + }, + "dependencies": { + "bluebird": "2.2.2", + "body-parser": "1.4.3", + "errorhandler": "1.1.1", + "express": "4.9.8", + "express-validator": "2.6.0", + "ini": "1.3.0", + "log4js": "0.6.21", + "nconf": "0.6.9" + }, + "devDependencies": { + "chai": "1.9.1", + "jshint": "2.5.2", + "mocha": "1.20.1", + "supertest": "0.13.0", + "supervisor": "~0.6.0" + } +} diff --git a/unleash-server/public/index.html b/unleash-server/public/index.html new file mode 100644 index 0000000000..9a1eb8d215 --- /dev/null +++ b/unleash-server/public/index.html @@ -0,0 +1 @@ +

Hello World

\ No newline at end of file diff --git a/unleash-server/public/scripts/hello.js b/unleash-server/public/scripts/hello.js new file mode 100644 index 0000000000..593ea39e37 --- /dev/null +++ b/unleash-server/public/scripts/hello.js @@ -0,0 +1 @@ +//hello world \ No newline at end of file diff --git a/unleash-server/server.js b/unleash-server/server.js new file mode 100644 index 0000000000..c4f76655a2 --- /dev/null +++ b/unleash-server/server.js @@ -0,0 +1,44 @@ +var express = require('express'), + bodyParser = require('body-parser'), + log4js = require('log4js'), + logger = require('./lib/logger'), + routes = require('./lib/routes'), + api = require('./lib/api'), + validator = require('express-validator'), + app = express(), + router = express.Router(), + baseUriPath = process.env.BASE_URI_PATH || ''; + +if(app.get('env') === 'development') { + app.use(require('errorhandler')()); +} + +app.use(validator([])); + +app.set('trust proxy'); +app.locals.baseUriPath = baseUriPath; + +app.use(log4js.connectLogger(logger, {format: ':remote-addr :status :method :url :response-timems'})); +app.set('port', process.env.HTTP_PORT || 4242); + +app.use(baseUriPath, express.static(__dirname + '/public')); +app.use(bodyParser.json({strict: false})); + +api(router); +routes(router); +app.use(baseUriPath, router); + +var server = app.listen(app.get('port'), function() { + logger.info('unleash started on ' + app.get('port')); +}); + +process.on('uncaughtException', function(err) { + logger.error('Uncaught Exception:', err.message); + logger.error(err.stack); +}); + + +module.exports = { + app: app, + server: server +}; \ No newline at end of file diff --git a/unleash-server/test/api.js b/unleash-server/test/api.js new file mode 100644 index 0000000000..013479eb47 --- /dev/null +++ b/unleash-server/test/api.js @@ -0,0 +1,12 @@ +var assert = require('assert'); + +describe('The api', function () { + beforeEach(function () { + // + }); + + it('returns all toggles', function (done) { + done(); + assert(true); + }); +}); \ No newline at end of file