diff --git a/.gitignore b/.gitignore index d1a8e31..f049c53 100755 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ db coverage docs dist -node_modules \ No newline at end of file +node_modules +angular-cms-db diff --git a/.travis.yml b/.travis.yml index 592b35a..5a392b8 100755 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ node_js: before_script: - 'npm install -g bower grunt-cli' - 'bower install' - - 'grunt --force' + - 'grunt -f -v' #- sleep 2 #- 'grunt serve' after_script: diff --git a/Gruntfile.js b/Gruntfile.js index 6f7de46..a19e399 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,20 +1,26 @@ - /* jshint camelcase:false */ 'use strict'; var fs = require('fs'), - express = require('express'), - cmsRouter = require('./routes/cms-router.js'), - config = JSON.parse(fs.readFileSync('./config/config.json')), - LIVERELOAD_PORT = 35729, - SERVER_PORT = process.env.PORT || 9000; + express = require('express'), + cmsRouter = require('./routes/cms-router.js'), + config = JSON.parse(fs.readFileSync('./config/config.json')), + LIVERELOAD_PORT = 35329, + SERVER_PORT = process.env.PORT || 9005; + + +var startNodeServer = function() { + var app = express(); + var router = new cmsRouter(config, app); + router.mount(); + + app.listen(config.port, function() { + console.log('express server listening on port: ' + config.port); + }); -var startNodeServer = function(){ - var _app = express(); - var server = new cmsRouter.mount(config, _app); }; -var serverEndpoint = 'http://127.0.0.1:8181'; +var serverEndpoint = 'http://127.0.0.1:' + config.port; var proxyConfig = { proxy: { forward: { @@ -27,16 +33,14 @@ var proxyConfig = { //var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT}); -var mountFolder = function (connect, dir) { +var mountFolder = function(connect, dir) { return connect.static(require('path').resolve(dir)); }; -module.exports = function (grunt) { +module.exports = function(grunt) { //Connect proxy to route requests to localhost:8181/api - grunt.loadNpmTasks('grunt-connect-proxy'); - grunt.loadNpmTasks('intern'); - require('json-proxy').initialize({}); + //require('json-proxy').initialize({}); require('load-grunt-tasks')(grunt); require('time-grunt')(grunt); @@ -96,7 +100,7 @@ module.exports = function (grunt) { options: { open: true, base: ['.tmp', '<%= yeoman.app %>'], - middleware: function (connect, options) { + middleware: function(connect, options) { startNodeServer(options, connect); return [ require('json-proxy').initialize(proxyConfig), @@ -119,7 +123,7 @@ module.exports = function (grunt) { keepAlive: true, open: true, base: '<%= yeoman.dist %>', - middleware: function (connect, options) { + middleware: function(connect, options) { return [ require('json-proxy').initialize(proxyConfig), mountFolder(connect, 'dist') @@ -131,7 +135,7 @@ module.exports = function (grunt) { options: { port: 9191, open: true, - middleware: function (connect, options) { + middleware: function(connect, options) { return [ mountFolder(connect, '.grunt'), mountFolder(connect, '.tmp'), @@ -152,20 +156,18 @@ module.exports = function (grunt) { //'Gruntfile.js' ], app: [ - '<%= yeoman.app %>/scripts', - '!<%= yeoman.app %>/scripts/libs' + '<%= yeoman.app %>/scripts', + '!<%= yeoman.app %>/scripts/libs' ] }, // Empties folders to start fresh clean: { dist: { - files: [ - { - dot: true, - src: ['.tmp', '<%= yeoman.dist %>/*', '!<%= yeoman.dist %>/.git*'] - } - ] + files: [{ + dot: true, + src: ['.tmp', '<%= yeoman.dist %>/*', '!<%= yeoman.dist %>/.git*'] + }] }, server: '.tmp' }, @@ -176,14 +178,12 @@ module.exports = function (grunt) { browsers: ['last 1 version'] }, dist: { - files: [ - { - expand: true, - cwd: '.tmp/styles/', - src: '{,*/}*.css', - dest: '.tmp/styles/' - } - ] + files: [{ + expand: true, + cwd: '.tmp/styles/', + src: '{,*/}*.css', + dest: '.tmp/styles/' + }] } }, @@ -195,48 +195,40 @@ module.exports = function (grunt) { sourceRoot: '' }, dist: { - files: [ - { - expand: true, - cwd: '<%= yeoman.app %>/scripts', - src: '{,*/}*.coffee', - dest: '.tmp/scripts', - ext: '.js' - } - ] + files: [{ + expand: true, + cwd: '<%= yeoman.app %>/scripts', + src: '{,*/}*.coffee', + dest: '.tmp/scripts', + ext: '.js' + }] }, test: { - files: [ - { - expand: true, - cwd: 'test', - src: '{,**/}*.{coffee,litcoffee,coffee.md}', - dest: '.tmp', - ext: '.js' - } - ] + files: [{ + expand: true, + cwd: 'test', + src: '{,**/}*.{coffee,litcoffee,coffee.md}', + dest: '.tmp', + ext: '.js' + }] }, e2e: { - files: [ - { - expand: true, - cwd: 'test/e2e', - src: '{,*/}*.coffee', - dest: '.tmp/e2e', - ext: '.js' - } - ] + files: [{ + expand: true, + cwd: 'test/e2e', + src: '{,*/}*.coffee', + dest: '.tmp/e2e', + ext: '.js' + }] }, routes: { - files: [ - { - expand: true, - cwd: 'routes', - src: '{,*/}*.coffee', - dest: '.tmp/routes', - ext: '.js' - } - ] + files: [{ + expand: true, + cwd: 'routes', + src: '{,*/}*.coffee', + dest: '.tmp/routes', + ext: '.js' + }] } }, @@ -305,26 +297,22 @@ module.exports = function (grunt) { // The following *-min tasks produce minified files in the dist folder imagemin: { dist: { - files: [ - { - expand: true, - cwd: '<%= yeoman.app %>/images', - src: '{,*/}*.{png,jpg,jpeg,gif}', - dest: '<%= yeoman.dist %>/images' - } - ] + files: [{ + expand: true, + cwd: '<%= yeoman.app %>/images', + src: '{,*/}*.{png,jpg,jpeg,gif}', + dest: '<%= yeoman.dist %>/images' + }] } }, svgmin: { dist: { - files: [ - { - expand: true, - cwd: '<%= yeoman.app %>/images', - src: '{,*/}*.svg', - dest: '<%= yeoman.dist %>/images' - } - ] + files: [{ + expand: true, + cwd: '<%= yeoman.app %>/images', + src: '{,*/}*.svg', + dest: '<%= yeoman.dist %>/images' + }] } }, htmlmin: { @@ -350,14 +338,12 @@ module.exports = function (grunt) { */ }, - files: [ - { - expand: true, - cwd: '<%= yeoman.app %>', - src: ['*.html', 'views/*.html'], - dest: '<%= yeoman.dist %>' - } - ] + files: [{ + expand: true, + cwd: '<%= yeoman.app %>', + src: ['*.html', 'views/*.html'], + dest: '<%= yeoman.dist %>' + }] } }, @@ -386,14 +372,12 @@ module.exports = function (grunt) { // minsafe compatible so Uglify does not destroy the ng references ngmin: { dist: { - files: [ - { - expand: true, - cwd: '.tmp/concat/scripts', - src: '*.js', - dest: '.tmp/concat/scripts' - } - ] + files: [{ + expand: true, + cwd: '.tmp/concat/scripts', + src: '*.js', + dest: '.tmp/concat/scripts' + }] } }, @@ -407,26 +391,23 @@ module.exports = function (grunt) { // Copies remaining files to places other tasks can use copy: { dist: { - files: [ - { - expand: true, - dot: true, - cwd: '<%= yeoman.app %>', - dest: '<%= yeoman.dist %>', - src: [ - '*.{ico,png,txt}', '.htaccess', - //'bower_components/**/*', - 'images/{,*/}*.{webp}', - 'fonts/*' - ] - }, - { - expand: true, - cwd: '.tmp/images', - dest: '<%= yeoman.dist %>/images', - src: ['generated/*'] - } - ] + files: [{ + expand: true, + dot: true, + cwd: '<%= yeoman.app %>', + dest: '<%= yeoman.dist %>', + src: [ + '*.{ico,png,txt}', '.htaccess', + //'bower_components/**/*', + 'images/{,*/}*.{webp}', + 'fonts/*' + ] + }, { + expand: true, + cwd: '.tmp/images', + dest: '<%= yeoman.dist %>/images', + src: ['generated/*'] + }] }, styles: { expand: true, @@ -550,7 +531,7 @@ module.exports = function (grunt) { dest: '.tmp/scripts/templates.js', options: { module: 'angularCmsApp', - url: function (url) { + url: function(url) { return url.replace('app/', ''); }, prefix: '', @@ -619,23 +600,13 @@ module.exports = function (grunt) { 'test/routes/*-spec.js' ] } - }, - intern: { - test: { - options: { - runType: 'client', - config: 'test/intern.conf', - reporters: [ 'console' ], - suites: [] - } - } } }; // Define the configuration for all the tasks grunt.initConfig(GruntConfig); - grunt.registerTask('serve', function (target) { + grunt.registerTask('serve', function(target) { if (target === 'dist') { return grunt.task.run(['build', 'connect:dist:keepalive']); } @@ -643,12 +614,12 @@ module.exports = function (grunt) { grunt.task.run(['clean:server', 'concurrent:server', 'autoprefixer', 'connect:livereload', 'watch']); }); - grunt.registerTask('server', function () { + grunt.registerTask('server', function() { grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.'); grunt.task.run(['serve']); }); - grunt.registerTask('test', function (target) { + grunt.registerTask('test', function(target) { grunt.task.run(['clean:server', 'concurrent:test', 'autoprefixer', 'connect:test']); if (target === 'e2e') { return grunt.task.run(['karma', 'protractor_webdriver', 'protractor', 'coveralls']); @@ -658,7 +629,7 @@ module.exports = function (grunt) { return grunt.task.run(['karma:unit', 'coveralls']); } }); - + grunt.registerTask('build', [ 'clean:dist', 'useminPrepare', @@ -669,7 +640,7 @@ module.exports = function (grunt) { 'ngtemplates', 'copy:dist', //'cdnify', - 'cssmin', + //'cssmin', 'uglify', 'rev', 'usemin' @@ -678,8 +649,8 @@ module.exports = function (grunt) { grunt.registerTask('ptor', ['coffee:test', 'protractor_webdriver', 'protractor']); grunt.registerTask('build-docs', ['useminPrepare', 'autoprefixer', 'concat', 'ngmin']); grunt.registerTask('docs', ['coffee', 'ngdocs', 'connect:docs', 'watch:scripts']); + grunt.registerTask('dist', ['docs', 'build']); grunt.registerTask('default', ['newer:jshint', 'test', 'build']); - grunt.registerTask('heroku:production', 'build'); grunt.registerTask('heroku:development', 'build'); }; diff --git a/app/.DS_Store b/app/.DS_Store index b532b2a..eb331ee 100644 Binary files a/app/.DS_Store and b/app/.DS_Store differ diff --git a/app/images/00000002 b/app/images/00000002 deleted file mode 100644 index c8cd16a..0000000 Binary files a/app/images/00000002 and /dev/null differ diff --git a/config/config.json b/config/config.json index 390bccf..1f1a7a8 100644 --- a/config/config.json +++ b/config/config.json @@ -1,174 +1,157 @@ { - "baseurl":"http://127.0.0.1:8181", - "sitetitle":"angular-cms", - "sitedesc":"This is the description", - "sitebrand":"/images/angular-cms-brand.png", - "sitecopy":"2014 ", - "version":"0.1", - "email":"jonniespratley@me.com", + "baseurl": "http://127.0.0.1:8181", + "sitetitle": "angular-cms", + "sitedesc": "This is the description", + "sitebrand": "/images/angular-cms-brand.png", + "sitecopy": "2014 ", + "version": "0.1", + "email": "jonniespratley@me.com", "host": "127.0.0.1", - "port":8181, - "apiBase":"/api/v2", - "version":"v2", - "security":{ - "salt":"angular-cms" + "port": 8585, + "apiBase": "/api/v2", + "version": "v2", + "security": { + "salt": "angular-cms" }, - "https":{ + "https": { "key": "./config/apache.key", - "cert":"./config/apache.crt" + "cert": "./config/apache.crt" }, - "db":{ - "name":"angular-cms", - "username":"angularcms-dev", - "password":"angularcms-dev", - "host":"paulo.mongohq.com:10089", - "port":31711, - "url":"angularcms-dev:angularcms-dev@paulo.mongohq.com:10089/app19632340" + "db": { + "name": "angular-cms", + "username": "angularcms-dev", + "password": "angularcms-dev", + "host": "paulo.mongohq.com:10089", + "port": 31711, + "url": "http://localhost:5984/angularcms", + "local": "angular-cms-db", + "remote": "http://localhost:5984/angularcms" }, - "email":{ - "username":"angular.cms@gmail.com", - "password":"isyourdaughter18?" + "email": { + "username": "angular.cms@gmail.com", + "password": "isyourdaughter18?" }, - "proxy":{ - "hostname":"127.0.0.1", - "port":5001 + "proxy": { + "hostname": "127.0.0.1", + "port": 5001 }, - "staticDir":"dist", - "publicDir":"www", - "uploadsTmpDir":".tmp", - "uploadsDestDir":"www/cms-content/uploads", - "uploadsUrl":"/cms-content/", - "logFormat":"[:date] - [:method] - :url - :status - :response-time ms", - "debug":true, - "feature":{ - "title":"angular-cms", - "body":"A content management system of some sort." + "staticDir": "dist", + "publicDir": "www", + "uploadsTmpDir": ".tmp", + "uploadsDestDir": "www/cms-content/uploads", + "uploadsUrl": "/cms-content/", + "logFormat": "[:date] - [:method] - :url - :status - :response-time ms", + "debug": true, + "feature": { + "title": "angular-cms", + "body": "A content management system of some sort." }, - "features":[ - { - "id":1, - "title":"HTML5", - "body":"Using HTML5 in every way to make a better user experience.", - "image":"/images/feature-html5.png" - }, - { - "id":2, - "title":"AngularJS", - "body":"The client-side framework of choice is Angular, its a full-stack.", - "image":"/images/feature-angular.png" - }, - { - "id":3, - "title":"Twitter Bootstrap", - "body":"The client-side UI of choice is Twitter Bootstrap 3.0.", - "image":"/images/feature-bootstrap.png" - }, - { - "id":4, - "title":"PhantomJS", - "body":"Fully testable with Jasmine Karma Runner Unit e2e with PhantomJS.", - "image":"/images/feature-phantomjs.png" - }, - { - "id":5, - "title":"NodeJS", - "body":"The server of choice is NodeJS, its fast and scalable.", - "image":"/images/feature-nodejs.png" - }, - { - "id":6, - "title":"MongoDB", - "body":"The database of choice is Mongo, its fast and scalable.", - "image":"/images/feature-mongodb.png" - } - ], - "session":{ - "authorized":false, - "user":null + "features": [{ + "id": 1, + "title": "HTML5", + "body": "Using HTML5 in every way to make a better user experience.", + "image": "/images/feature-html5.png" + }, { + "id": 2, + "title": "AngularJS", + "body": "The client-side framework of choice is Angular, its a full-stack.", + "image": "/images/feature-angular.png" + }, { + "id": 3, + "title": "Twitter Bootstrap", + "body": "The client-side UI of choice is Twitter Bootstrap 3.0.", + "image": "/images/feature-bootstrap.png" + }, { + "id": 4, + "title": "PhantomJS", + "body": "Fully testable with Jasmine Karma Runner Unit e2e with PhantomJS.", + "image": "/images/feature-phantomjs.png" + }, { + "id": 5, + "title": "NodeJS", + "body": "The server of choice is NodeJS, its fast and scalable.", + "image": "/images/feature-nodejs.png" + }, { + "id": 6, + "title": "MongoDB", + "body": "The database of choice is Mongo, its fast and scalable.", + "image": "/images/feature-mongodb.png" + }], + "session": { + "authorized": false, + "user": null }, - "layout":{ - "header":"views/_header.html", - "sidebar":"views/_sidebar.html", - "content":"views/_content.html", - "footer":"views/_footer.html" + "layout": { + "header": "views/_header.html", + "sidebar": "views/_sidebar.html", + "content": "views/_content.html", + "footer": "views/_footer.html" }, - "theme":"default", - "templates":{ - "compiled":"/dist/templates.html", - "uncompiled":"/views" + "theme": "default", + "templates": { + "compiled": "/dist/templates.html", + "uncompiled": "/views" }, - "menu":{ - "admin":[ - { - "id":1, - "title":"Pages", - "href":"/pages", - "icon":"edit" - }, - { - "id":1, - "title":"Plugins", - "href":"/plugins", - "icon":"folder-open" - }, - { - "id":1, - "title":"Widgets", - "href":"/widgets", - "icon":"puzzle-piece" - }, - { - "id":1, - "title":"Media", - "href":"/media", - "icon":"cloud-download" - }, - { - "id":1, - "title":"Users", - "href":"/users", - "icon":"group" - }, - { - "id":1, - "title":"Themes", - "href":"/themes", - "icon":"camera" - }, - { - "id":1, - "title":"Settings", - "href":"/settings", - "icon":"cog" - } - ], - "pub":[ + "menu": { + "admin": [{ + "id": 1, + "title": "Pages", + "href": "/pages", + "icon": "edit" + }, { + "id": 1, + "title": "Plugins", + "href": "/plugins", + "icon": "folder-open" + }, { + "id": 1, + "title": "Widgets", + "href": "/widgets", + "icon": "puzzle-piece" + }, { + "id": 1, + "title": "Media", + "href": "/media", + "icon": "cloud-download" + }, { + "id": 1, + "title": "Users", + "href": "/users", + "icon": "group" + }, { + "id": 1, + "title": "Themes", + "href": "/themes", + "icon": "camera" + }, { + "id": 1, + "title": "Settings", + "href": "/settings", + "icon": "cog" + }], + "pub": [ ], - "user":[ - { - "id":1, - "title":"Dashboard", - "icon":"dashboard", - "href":"/dashboard" - }, - { - "id":2, - "title":"My Profile", - "icon":"user", - "href":"/profile" - }, - { - "id":3, - "title":"Help", - "icon":"book", - "href":"/help" - } - ] + "user": [{ + "id": 1, + "title": "Dashboard", + "icon": "dashboard", + "href": "/dashboard" + }, { + "id": 2, + "title": "My Profile", + "icon": "user", + "href": "/profile" + }, { + "id": 3, + "title": "Help", + "icon": "book", + "href": "/help" + }] }, - "settings":{ - "currentdate":"2014-12-17T06:14:20.114Z", - "dateformats":[ + "settings": { + "currentdate": "2014-12-17T06:14:20.114Z", + "dateformats": [ "medium", "short", "fullDate", @@ -176,97 +159,85 @@ "mediumDate", "shortDate" ], - "timeformats":[ + "timeformats": [ "mediumTime", "shortTime" ], - "dateformat":"medium", - "timeformat":"shortTime", - "timezone":null, - "servers":[ - { - "name":"apiv1", - "host":"127.1.0.1", - "port":3000, - "body":"This is the v1 api server" - }, - { - "name":"apiv2", - "host":"127.1.0.1", - "port":3000, - "body":"This is the v2 api server" - } - ], - "socketio":{ - "host":"127.1.0.1", - "port":8081 + "dateformat": "medium", + "timeformat": "shortTime", + "timezone": null, + "servers": [{ + "name": "apiv1", + "host": "127.1.0.1", + "port": 3000, + "body": "This is the v1 api server" + }, { + "name": "apiv2", + "host": "127.1.0.1", + "port": 3000, + "body": "This is the v2 api server" + }], + "socketio": { + "host": "127.1.0.1", + "port": 8081 }, - "network":{ - "online":true, - "cache":true + "network": { + "online": true, + "cache": true }, - "database":{ - "host":"127.1.0.1", - "port":27017, - "name":"angular-cms" + "database": { + "host": "127.1.0.1", + "port": 27017, + "name": "angular-cms" }, - "api":{ - "url":"", - "endpoint":"/api/", - "version":"v2", - "versions":[ + "api": { + "url": "", + "endpoint": "/api/", + "version": "v2", + "versions": [ "v1", "v2" ] }, - "live":false, - "debug":true, - "version":"0.0.1", - "formFactor":"desktop", - "currentOrientation":null, - "cdn":"http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms", - "cdns":{ - "http":"http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms", - "https":"https://4ac535c4a3d1d3359bbc-b2b68ced242ecf1cb9bc1021688e3775.ssl.cf1.rackcdn.com/angular-cms", - "streaming":"http://df86ce1cf0cf1f552fe2-b2b68ced242ecf1cb9bc1021688e3775.r49.stream.cf1.rackcdn.com/angular-cms" + "live": false, + "debug": true, + "version": "0.0.1", + "formFactor": "desktop", + "currentOrientation": null, + "cdn": "http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms", + "cdns": { + "http": "http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms", + "https": "https://4ac535c4a3d1d3359bbc-b2b68ced242ecf1cb9bc1021688e3775.ssl.cf1.rackcdn.com/angular-cms", + "streaming": "http://df86ce1cf0cf1f552fe2-b2b68ced242ecf1cb9bc1021688e3775.r49.stream.cf1.rackcdn.com/angular-cms" } }, - "options":{ - "layouts":[ - { - "id":0, - "name":"Fixed", - "value":"container" - }, - { - "id":1, - "name":"Fluid", - "value":"container-fluid" - } - ], - "sidebars":[ - { - "id":1, - "name":"Default", - "value":"sidebar", - "url":"/views/partials/sidebar.html" - } - ], - "navbars":[ - { - "id":1, - "name":"Default", - "value":"navbar", - "url":"/views/partials/navbar.html" - } - ], - "backgrounds":[ - { - "id":0, - "title":"Default" - } - ], - "themes":[ + "options": { + "layouts": [{ + "id": 0, + "name": "Fixed", + "value": "container" + }, { + "id": 1, + "name": "Fluid", + "value": "container-fluid" + }], + "sidebars": [{ + "id": 1, + "name": "Default", + "value": "sidebar", + "url": "/views/partials/sidebar.html" + }], + "navbars": [{ + "id": 1, + "name": "Default", + "value": "navbar", + "url": "/views/partials/navbar.html" + }], + "backgrounds": [{ + "id": 0, + "title": "Default" + }], + "themes": [ "Default", "Amelia", "Cerulean", @@ -282,17 +253,17 @@ "Yeti" ] }, - "logout":{ - "redirect":"#/login", - "message":"Good bye..." + "logout": { + "redirect": "#/login", + "message": "Good bye..." }, - "login":{ - "logo":"https://7fd8f70e662929940bdd-79dc9bd5ca0b6e6cb6f16ffd7b1e05e2.ssl.cf1.rackcdn.com/img/logo-login-med.png", - "redirect":"/#/home", - "user":{ - "username":"", - "password":"" + "login": { + "logo": "https://7fd8f70e662929940bdd-79dc9bd5ca0b6e6cb6f16ffd7b1e05e2.ssl.cf1.rackcdn.com/img/logo-login-med.png", + "redirect": "/#/home", + "user": { + "username": "", + "password": "" }, - "message":"Welcome {{user.username}}" + "message": "Welcome {{user.username}}" } } diff --git a/package.json b/package.json old mode 100755 new mode 100644 index 2963512..8f8d985 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-cms", - "version": "0.0.1", + "version": "0.0.2", "description": "This is a lightweight CMS built with Angular.js, Twitter Bootstrap and Node.js.", "author": "Jonnie Spratley", "license": "MIT", @@ -20,8 +20,8 @@ }, "keywords": [ "angular", - "grunt", "angular-cms", + "grunt", "yeoman" ], "dependencies": { @@ -40,6 +40,7 @@ "express-session": "^1.9.3", "finalhandler": "^0.3.3", "fs-extra": "^0.12.0", + "grunt": "^0.4.5", "http-proxy": "^1.3.0", "jade": "^1.8.2", "jps-ds": "~0.0.2", @@ -47,17 +48,17 @@ "jquery-file-upload-middleware": "~0.1.1", "jshint-stylish": "~0.1.5", "json-proxy": "^0.3.0", + "karma": "^0.12.37", "logfmt": "~0.18.1", "markdown": "~0.5.0", "method-override": "~1.0.0", - "mongodb": "^1.4.23", - "mongoose": "^3.8.20", "passport": "^0.2.1", "passport-facebook": "^1.0.3", "passport-google": "^0.3.0", "passport-http": "^0.2.2", "passport-local": "^1.0.0", "passport-twitter": "^1.0.2", + "pouchdb": "^3.6.0", "promised-io": "~0.3.4", "q": "^1.1.2", "request": "~2.34.0", @@ -111,7 +112,6 @@ "gulp-protractor": "0.0.12", "gulp-server-livereload": "^1.0.1", "gulp-uglify": "^1.0.2", - "intern": "^2.2.2", "jasmine-core": "^2.1.2", "jasmine-node": "~1.11.0", "jasmine-reporters": "^1.0.1", @@ -138,7 +138,7 @@ "npm": "1.3.x" }, "scripts": { - "test": "grunt test", - "start": "node server.js" + "start": "node server.js", + "test": "grunt test" } } diff --git a/routes/cms-auth.js b/routes/cms-auth.js index ac44b92..03e4da8 100644 --- a/routes/cms-auth.js +++ b/routes/cms-auth.js @@ -1,9 +1,13 @@ -var bodyParser = require('body-parser'), mongoose = require('mongoose'), util = require('util'), User = require('./models/user'), session = require('express-session'), -crypto = require('crypto'), -bcrypt = require('bcrypt-nodejs'); +var bodyParser = require('body-parser'), + mongoose = require('mongoose'), + util = require('util'), + User = require('./models/user'), + session = require('express-session'), + crypto = require('crypto'), + bcrypt = require('bcrypt-nodejs'); var cmsAuth = function(config, app) { - console.warn('cms-auth'); + console.warn('cms-auth initialized'); //### hashPassword //Hash password using basic sha1 hash. @@ -19,7 +23,7 @@ var cmsAuth = function(config, app) { * @param res * @param next */ - login : function(req, res, next) { + login: function(req, res, next) { var query = {}; if (req.body.username) { query.username = req.body.username; @@ -30,7 +34,7 @@ var cmsAuth = function(config, app) { query.password = hashPassword(req.body.password, query.username); console.warn('trying to login', query); User.findOne({ - username : query.username + username: query.username }, function(err, data) { if (err) { return res.jsonp(400, err); @@ -41,12 +45,12 @@ var cmsAuth = function(config, app) { return res.json(200, data); } else { return res.json(404, { - message : 'Wrong username/password!' + message: 'Wrong username/password!' }); } } catch (error) { return res.json(404, { - message : error + message: error }); } }); @@ -57,7 +61,7 @@ var cmsAuth = function(config, app) { * @param res * @param next */ - register : function(req, res, next) { + register: function(req, res, next) { var data = req.body; //TODO: Need to make this externalized. @@ -78,27 +82,27 @@ var cmsAuth = function(config, app) { //Try and find user User.find({ - username : data.username + username: data.username }, function(err, u) { console.log('found user', err, util.inspect(u, { - colors : true + colors: true })); var user = new User(data); if (err) { res.jsonp(400, { - message : 'Problem registering!' + message: 'Problem registering!' }); } if (u.length) { res.jsonp(400, { - message : 'Username already exists!' + message: 'Username already exists!' }); } else { user.save(function(er, ok) { if (er) { return res.jsonp(400, { - message : 'Problem registering!' + message: 'Problem registering!' }); } else { return res.jsonp(201, ok); @@ -108,22 +112,22 @@ var cmsAuth = function(config, app) { }); }, - session : function(req, res, next) { + session: function(req, res, next) { var user = req.session; if (req.session && req.session.user) { user = req.session.user; } console.warn(util.inspect(user, { - colors : true + colors: true })); return res.send({ - message : 'Your session', - data : user + message: 'Your session', + data: user }); } }; - + app.get(config.apiBase + '/login', bodyParser.json(), cmsAuth.login); app.post(config.apiBase + '/login', bodyParser.json(), cmsAuth.login); app.post(config.apiBase + '/register', bodyParser.json(), cmsAuth.register); diff --git a/routes/cms-db.js b/routes/cms-db.js index 8627df6..1792b69 100644 --- a/routes/cms-db.js +++ b/routes/cms-db.js @@ -2,34 +2,6 @@ var mongoose = require('mongoose'); module.exports = function(config) { console.warn('cms-db initialized'); - try { - mongoose.connect(config.db.url); - } catch (err) { - throw new Error('Unable to connect to MongoDB at ' + config.db.url); - } - // CONNECTION EVENTS - // When successfully connected - mongoose.connection.on('connected', function() { - console.log('Mongoose default connection open to ', config.db.url); - }); - // If the connection throws an error - mongoose.connection.on('error', function(err) { - console.log('Mongoose default connection error: ' + err); - }); - - // When the connection is disconnected - mongoose.connection.on('disconnected', function() { - console.log('Mongoose default connection disconnected'); - }); - - // If the Node process ends, close the Mongoose connection - process.on('SIGINT', function() { - mongoose.connection.close(function() { - console.log('Mongoose default connection disconnected through app termination'); - process.exit(0); - }); - }); - -}; \ No newline at end of file +}; diff --git a/routes/cms-proxy.js b/routes/cms-proxy.js index 49c938e..e83395b 100644 --- a/routes/cms-proxy.js +++ b/routes/cms-proxy.js @@ -3,22 +3,22 @@ var fs = require('fs'), httpProxy = require('http-proxy'); -module.exports = function (config, app) { - console.warn( 'cms-proxy', 'initialized', config.proxy ); +module.exports = function(config, app) { + console.warn('cms-proxy', 'initialized', config.proxy); /** - * @TODO - HTTPS Key and Cert - * - * This is the location of your https cert and key. - */ + * @TODO - HTTPS Key and Cert + * + * This is the location of your https cert and key. + */ var httpsKey = fs.readFileSync(config.https.key).toString(); var httpsCert = fs.readFileSync(config.https.cert).toString(); /** - * @TODO - Proxy Options - * This object holds options used for creating a proxy server. - */ + * @TODO - Proxy Options + * This object holds options used for creating a proxy server. + */ var options = { port: 8080, host: { @@ -51,15 +51,6 @@ module.exports = function (config, app) { port: options.api.port }); util.log('Routing request: API server'.warn); - } - else if (req.url.match(/^\/1\//)) { - - /* Default express server */ - proxy.proxyRequest(req, res, { - host: 'api.parse.com' - }); - util.log('Routing request: Parse Server'.warn); - } else { /* Default express server */ @@ -73,7 +64,7 @@ module.exports = function (config, app) { //Start the proxy server - proxyServer.listen(config.proxy.port, function(){ + proxyServer.listen(config.proxy.port, function() { console.log('cms-proxy server listening on ', config.proxy.port); }); }; diff --git a/routes/cms-rest.js b/routes/cms-rest.js index a411e5e..f3aa068 100644 --- a/routes/cms-rest.js +++ b/routes/cms-rest.js @@ -1,28 +1,28 @@ var express = require('express'), - bodyParser = require( 'body-parser' ), - session = require( 'express-session' ), - RestResource = require( './rest' ); + bodyParser = require('body-parser'), + session = require('express-session'), + RestResource = require('./rest'); -module.exports = function (config, app) { +module.exports = function(config, app) { 'use strict'; var router = express.Router(); - router.use(function (req, res, next) { + router.use(function(req, res, next) { console.log('cms-rest Time:', Date.now()); next(); }); - router.get( config.apiBase, RestResource.index ); - router.get( config.apiBase + '/plugins', RestResource.plugins ); - router.get( config.apiBase + '/readme', RestResource.readme ); + router.get(config.apiBase, RestResource.index); + router.get(config.apiBase + '/plugins', RestResource.plugins); + router.get(config.apiBase + '/readme', RestResource.readme); //Dynamic REST - router.get( config.apiBase + '/:db/:collection/:id?', RestResource.get ); - router.post( config.apiBase + '/:db/:collection/:id?', bodyParser.json(), RestResource.add ); - router.put( config.apiBase + '/:db/:collection/:id?', bodyParser.json(), RestResource.edit ); - router.delete( config.apiBase + '/:db/:collection/:id?', RestResource.destroy ); + router.get(config.apiBase + '/:db/:id?', RestResource.get); + router.post(config.apiBase + '/:db/:id?', bodyParser.json(), RestResource.add); + router.put(config.apiBase + '/:db/:id?', bodyParser.json(), RestResource.edit); + router.delete(config.apiBase + '/:db/:id?', RestResource.destroy); - console.warn( 'cms-rest', 'initialized' ); + console.warn('cms-rest', 'initialized'); app.use('/', router); }; diff --git a/routes/cms-router.js b/routes/cms-router.js index 126acd3..e8ccac4 100644 --- a/routes/cms-router.js +++ b/routes/cms-router.js @@ -1,18 +1,36 @@ -var http = require('http'), util = require('util'); +var util = require('util'); +var express = require('express'); -module.exports.mount = function(config, app) { +module.exports = function(config, app) { 'use strict'; - + var router = express.Router(); + router.use(function(req, res, next) { + console.log('cms-router Time:', Date.now()); + next(); + }); + //Fix for cloud foundry - if(process.env.VCAP_APP_PORT ){ + if (process.env.VCAP_APP_PORT) { config.port = process.env.VCAP_APP_PORT; } - - var server = http.createServer(app); + // TODO: Using pouchdb + var PouchDB = require('pouchdb'); + PouchDB.debug('*'); + + var db = new PouchDB(config.db.local); + app.locals.db = db; + + + db.info().then(function(resp) { + console.log('Connected to', config.db.local, resp); + }); + + var serverPort = process.env.PORT || config.port; var serverHost = process.env.IP || config.host; + require('./cms-db')(config); require('./cms-auth')(config, app); require('./cms-passport')(config, app); @@ -20,14 +38,12 @@ module.exports.mount = function(config, app) { require('./cms-server')(config, app); require('./cms-rest')(config, app); require('./cms-proxy')(config, app); - require('./cms-sockets')(config, server); - - - - - - - server.listen(config.port, function() { - util.log('App listening on port: ' + config.port + ''.verbose); - }); + //require('./cms-sockets')(config, server); + + this.mount = function() { + console.warn('cms-router', 'mounted'); + + app.use('/', router); + }; + }; diff --git a/routes/rest.js b/routes/rest.js index 3c7d3f9..0e88edf 100755 --- a/routes/rest.js +++ b/routes/rest.js @@ -16,20 +16,17 @@ */ //## Required Modules -var crypto = require('crypto'); -var path = require('path'); -var express = require('express'); -var path = require('path'); //used for file path -var fs = require('fs-extra'); //File System - for file manipulatio -var util = require('util'); -var request = require('request'); - -var sio = require('socket.io'); -var Deferred = require("promised-io/promise").Deferred; -var when = require("promised-io/promise"); -var bodyParser = require('body-parser'); -var busboy = require('connect-busboy'); -var markdown = require("markdown").markdown; +var crypto = require('crypto'), + express = require('express'), + path = require('path'), + fs = require('fs-extra'), + util = require('util'), + request = require('request'); +var Deferred = require("promised-io/promise").Deferred, + when = require("promised-io/promise"), + bodyParser = require('body-parser'), + busboy = require('connect-busboy'), + markdown = require("markdown").markdown; //Strings for results @@ -40,114 +37,49 @@ var MESSAGES = { }; var config = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../config/config.json'))); -var DS = require('jps-ds').DS; -var _ds = new DS({ - host: config.db.url, - //host: 'localhost/angular-cms', - models: { - 'groups': { - title: String, - body: String, - slug: String, - created: Date, - updated: Date - }, - 'users': { - id: String, - provider: String, - displayName: String, - name: Object, - emails: Array, - photos: Array, - username: String, - email: String, - password: String, - active: Boolean, - meta: Object, - token: String, - created: Date, - updated: Date - }, - 'uploads': { - title: String, - body: String, - image: String, - path: String, - filename: String, - meta: Object, - created: Date, - updated: Date, - userid: String - }, - 'posts': { - title: String, - body: String, - image: Object, - type: String, - published: Boolean, - created: Date, - updated: Date, - status: Object, - parent: Object, - template: Object, - order: Number, - meta: Object - }, - 'pages': { - title: String, - body: String, - image: Object, - type: String, - published: Boolean, - created: Date, - updated: Date, - status: Object, - parent: Object, - template: Object, - order: Number, - meta: Object - }, - 'themes': {}, - 'widgets': { - title: String, - body: String, - path: String, - filename: String, - meta: Object, - created: Date, - updated: Date, - userid: String, - active: Boolean - }, - 'plugins': { - title: String, - body: String, - path: String, - filename: String, - meta: Object, - created: Date, - updated: Date, - userid: String, - active: Boolean - } + + + +// TODO: Using pouchdb +var PouchDB = require('pouchdb'); +PouchDB.debug('*'); +var db = new PouchDB(config.db.local); +var _ds = { + findOne: function(id, params) { + return db.get(id, params); + }, + findAll: function(params) { + return db.allDocs(params); + }, + create: function(id, data) { + return db.put(data, id); + }, + update: function(id, data) { + return db.get(id).then(function(resp) { + data._rev = resp._rev; + return db.put(data, id); + }) + }, + remove: function(id) { + return db.get(id).then(function(resp) { + return db.remove(resp); + }) } -}); +}; + + function delay(ms, value) { - // create a new Deferred var deferred = new Deferred(); - setTimeout(function () { - // fulfill the deferred/promise, all listeners to the promise will be notified, and - // provided the value as the value of the promise + setTimeout(function() { deferred.resolve(value); }, ms); - // return the promise that is associated with the Deferred object return deferred.promise; } //### hashPassword //Hash password using basic sha1 hash. -var hashPassword = function (pass, salt) { +var hashPassword = function(pass, salt) { var shasum = crypto.createHash('sha1'); shasum.update(salt + pass); @@ -179,7 +111,7 @@ colors.setTheme({ //I am a RESTful resource object for handling CRUD operations on v1 or v2 api. var RestResource = { config: null, - init: function (config) { + init: function(config) { this.config = config; return this; }, @@ -188,13 +120,15 @@ var RestResource = { v1: 'https://www..com', v2: '/api/v2/' }, - log: function () { - console.log(util.inspect(arguments, {colors: true})); + log: function() { + console.log(util.inspect(arguments, { + colors: true + })); }, //### index //I handle displaying a message with the version for this api. - index: function (req, res, next) { + index: function(req, res, next) { res.json({ message: 'REST API Server ' + RestResource.useversion }); @@ -202,61 +136,60 @@ var RestResource = { //### get //I handle gathering records dynamically from a call to the v2 api. - get: function (req, res, next) { - if (req.param('id')) { + get: function(req, res, next) { + if (req.params.id) { console.log('find one', req.params.id); - _ds.findOne(req.params.collection, req.params.id).then(function (data) { + _ds.findOne(req.params.id, req.params).then(function(data) { res.send(data); - }, function (err) { + }, function(err) { res.send(err); }); } else { - _ds.findAll(req.params.collection).then(function (data) { + _ds.findAll(req.params).then(function(data) { res.send(data); - }, function (err) { + }, function(err) { res.send(err); }); } }, //### add //I handle adding a record to the database. - add: function (req, res, next) { - _ds.create(req.params.collection, req.body).then(function (data) { + add: function(req, res, next) { + _ds.create(req.body).then(function(data) { console.warn('create', data); res.send(data); - }, function (err) { + }, function(err) { res.send(err); }); }, //### edit //I handle - edit: function (req, res, next) { + edit: function(req, res, next) { var data = req.body; delete data._id; - _ds.update(req.params.collection, req.params.id, data).then(function (data) { + _ds.update(req.params.id, data).then(function(data) { console.warn(data); res.send(data); - }, function (err) { + }, function(err) { res.send(err); }); }, //### view //I handle - view: function (req, res, next) { - }, + view: function(req, res, next) {}, //### destroy //I handle - destroy: function (req, res, next) { - _ds.destroy(req.params.collection, req.params.id).then(function (data) { + destroy: function(req, res, next) { + _ds.destroy(req.params.id).then(function(data) { console.warn(data); res.send(data); - }, function (err) { + }, function(err) { res.send(err); }); }, - readme: function (res, req) { + readme: function(res, req) { var localPath = __dirname + '/../README.md'; - fs.readFile(localPath, 'utf8', function (err, data) { + fs.readFile(localPath, 'utf8', function(err, data) { if (err) { req.end('There was an error.'); return console.log(err); @@ -270,8 +203,8 @@ var RestResource = { console.log(data); }); }, - plugins: function (req, res) { - var result = fs.readdir('./app/cms-plugins', function (err, files) { + plugins: function(req, res) { + var result = fs.readdir('./app/cms-plugins', function(err, files) { console.log(files); res.header('Content-Type', 'application/json'); res.jsonp(200, files); @@ -283,8 +216,7 @@ var RestResource = { //### getFile //Get file contents from a file. function getFile(localPath, mimeType, res) { - - fs.readFile(localPath, 'utf8', function (err, data) { + fs.readFile(localPath, 'utf8', function(err, data) { if (err) { res.end('There was an error.'); return console.log(err); @@ -303,10 +235,9 @@ function getFile(localPath, mimeType, res) { //### writeFile //Write contents to a file function writeFile(localPath, contents) { - // create a stream, and create the file if it doesn't exist stream = fs.createWriteStream(localPath); console.log('writeFile', localPath); - stream.on("open", function () { + stream.on("open", function() { // write to and close the stream at the same time stream.end(contents, 'utf-8'); res.end(html); diff --git a/server.js b/server.js index b3a11ac..ad770ea 100755 --- a/server.js +++ b/server.js @@ -2,22 +2,30 @@ * Server - This is the Node.js Server. * @object */ -var express = require('express'); + var fs = require('fs'); var cmsRouter = require('./routes/cms-router.js'); -var app = express(); + var config = JSON.parse(fs.readFileSync('./config/config.json')); //Test if services -if(process.env.VCAP_SERVICES){ +if (process.env.VCAP_SERVICES) { var cloudServices = JSON.parse(process.env.VCAP_SERVICES); console.warn('cloud services', cloudServices); //var dbcreds = services['mongodb'][0].credentials; } -var port = process.env.PORT || 1339; + +var port = process.env.PORT || config.port; var host = process.env.VCAP_APP_HOST || "127.0.0.1"; config.host = host; config.port = port; -var server = new cmsRouter.mount(config, app); -console.log(server); + +var express = require('express'); +var app = express(); +var router = new cmsRouter(config, app); +router.mount(); + +app.listen(port, function() { + console.log('express server listening on port: ' + port); +}); diff --git a/www/views/main.html b/www/views/main.html index a3d533d..67819b7 100644 --- a/www/views/main.html +++ b/www/views/main.html @@ -8,7 +8,6 @@
{{App.feature.body}} -