diff --git a/ecosystem.json b/ecosystem.json new file mode 100644 index 0000000..a9374ae --- /dev/null +++ b/ecosystem.json @@ -0,0 +1,21 @@ +{ + /** + * Application configuration section + * http://pm2.keymetrics.io/docs/usage/application-declaration/ + */ + apps : [ + + // First application + { + name : "Obrand Admin Server", + script : "obrand-server.js", + env: { + COMMON_VARIABLE: "true" + }, + env_production : { + NODE_ENV: "production" + } + } + ] + +} diff --git a/server/app/accounts.js b/server/app/accounts.js index 63448ba..5759689 100644 --- a/server/app/accounts.js +++ b/server/app/accounts.js @@ -1,4 +1,3 @@ -'use strict'; var db = require('../units/db-connector').dbConnection; var dbAccounts = require('../units/db-accounts')(db); module.exports = function(app) { @@ -20,7 +19,6 @@ module.exports = function(app) { } } }; - console.log(response); res.status(200).send(response); }) .catch(function(err) { diff --git a/server/app/beacon.js b/server/app/beacon.js index 513cc46..61c1d7d 100644 --- a/server/app/beacon.js +++ b/server/app/beacon.js @@ -6,7 +6,7 @@ * */ /*jshint node:true*/ -'use strict'; + var db = require('../units/db-connector').dbConnection; var dbPages = require('../units/db-pages')(db); @@ -17,25 +17,22 @@ module.exports = function(app) { var beaconRouter = express.Router(); beaconRouter.get('/', function(req, res) { + 'use strict'; var beacon = {}; if (req.headers.hasOwnProperty('beacon')) { beacon = JSON.parse(req.headers.beacon); + logger.debug(beacon); } - /* res.send({ - beacon: beacon - });*/ logger.info('gettingLatestAddedPage'); dbPages.getLatestAddedPage() .then((d) => { - logger.debug(d); - //res.status(407).end(); res.redirect(301, d.fullpath); }).catch((err)=> { - console.error(err); - res.status(401).end(); - }); + console.error(err); + res.status(401).end(); + }); }); diff --git a/server/app/companies.js b/server/app/companies.js index 09156ba..db0b2a3 100644 --- a/server/app/companies.js +++ b/server/app/companies.js @@ -1,5 +1,4 @@ /*jshint node:true*/ -'use strict'; var db = require('../units/db-connector').dbConnection; var dbCompany = require('../units/db-company')(db); var $U = require('md-utils'); @@ -9,6 +8,7 @@ module.exports = function(app) { var companiesRouter = express.Router(); companiesRouter.get('/:id', function(req, res) { + 'use strict'; var id = req.params.id; dbCompany.sqlGetSimpleCompany(id) .then(function(data) { @@ -18,7 +18,6 @@ module.exports = function(app) { type: 'company', id: id, attributes: $U.reDashObject(data) } }; - console.log(response); res.status(200).send(response); }) .catch(function(err) { @@ -27,25 +26,9 @@ module.exports = function(app) { }); }); - - - companiesRouter.post('/', function(req, res) { - res.status(201).end(); - }); - - companiesRouter.get('/:id', function(req, res) { - res.send({ - companies: { - id: req.params.id - } - }); - }); - companiesRouter.patch('/:id', function(req, res) { - + 'use strict'; if (/Bearer .+/.test(req.headers.authorization)) { - console.log('Patching: ' + req.params.id); - console.log(req.body.data); var updateData = $U.unDashObject(req.body.data.attributes); dbCompany.addNewCompany(updateData) .then(function(d) { @@ -71,16 +54,7 @@ module.exports = function(app) { res.status(204).end(); }); - // The POST and PUT call will not contain a request body - // because the body-parser is not included by default. - // To use req.body, run: - - // Npm install --save-dev body-parser app.use('/api/companies', require('body-parser').json({type: 'application/vnd.api+json'})); - // After installing, you need to `use` the body-parser for - // this mock uncommenting the following line: - // - //App.use('/api/companies', require('body-parser').json()); app.use('/api/companies', companiesRouter); }; diff --git a/server/app/newcompanies.js b/server/app/newcompanies.js index a88f225..43bf5ef 100644 --- a/server/app/newcompanies.js +++ b/server/app/newcompanies.js @@ -1,10 +1,11 @@ /*jshint node:true*/ -'use strict'; + var db = require('../units/db-connector').dbConnection; var dbCompany = require('../units/db-company')(db); var dbAccounts = require('../units/db-accounts')(db); var $U = require('md-utils'); var events = require('events'); + // Create an eventEmitter object var eventEmitter = new events.EventEmitter(); @@ -13,7 +14,7 @@ module.exports = function(app) { var newcompaniesRouter = express.Router(); eventEmitter.on('makeMemberOf', (uid, cid) => { - console.log('Make ' + uid + ' a member of ' + cid); + 'use strict'; dbAccounts.makeMemberOf(uid, cid) .catch(function(err) { console.error(err); @@ -27,6 +28,7 @@ module.exports = function(app) { }); newcompaniesRouter.post('/', function(req, res) { + 'use strict'; var updateData = $U.unDashObject(req.body.data.attributes); if (/Bearer .+/.test(req.headers.authorization)) { dbCompany.addNewCompany(updateData) @@ -49,35 +51,7 @@ module.exports = function(app) { } }); - newcompaniesRouter.get('/:id', function(req, res) { - res.send({ - newcompanies: { - id: req.params.id - } - }); - }); - - newcompaniesRouter.put('/:id', function(req, res) { - res.send({ - newcompanies: { - id: req.params.id - } - }); - }); - - newcompaniesRouter.delete('/:id', function(req, res) { - res.status(204).end(); - }); - - // The POST and PUT call will not contain a request body - // because the body-parser is not included by default. - // To use req.body, run: - - // Npm install --save-dev body-parser app.use('/api/newcompanies', require('body-parser').json({type: 'application/vnd.api+json'})); - // After installing, you need to `use` the body-parser for - // this mock uncommenting the following line: - app.use('/api/newcompanies', newcompaniesRouter); }; diff --git a/server/app/pages.js b/server/app/pages.js index 25169ab..b09665b 100644 --- a/server/app/pages.js +++ b/server/app/pages.js @@ -17,15 +17,11 @@ var templates = { var exportPath = __dirname + '/../static/'; -var eventRenderPage = (page) => { - console.log('+++ eventRenderPage'); - doRenderPage(page); -}; var doRenderPage = (page) => { - console.log('+ doRenderPage'); - var compiledhtml, _page = $U.unDashObject(page); + var compiledhtml; + var _page = $U.unDashObject(page); var htmlfile = exportPath + _page.pid + '.html'; if (templates.basic.compiled === null) { @@ -35,7 +31,11 @@ var doRenderPage = (page) => { compiledhtml = templates.basic.compiled(_page); fs.writeFileSync(htmlfile, compiledhtml); - console.log('- doRenderPage'); + +}; + +var eventRenderPage = (page) => { + doRenderPage(page); }; eventHandler.on('renderPage', eventRenderPage); @@ -46,12 +46,9 @@ module.exports = function(app) { pagesRouter.get('/', function(req, res) { - console.log(req.query.filter); dbPages.getFullPageList() .then(function(data) { - // console.log(util.inspect(data)); - const response = { data: data }; @@ -59,28 +56,24 @@ module.exports = function(app) { res.status(200).send(response); }).catch((err)=> { - console.error(err); - res.status(401).end(); - }); + console.error(err); + res.status(401).end(); + }); }); pagesRouter.get('/list', function(req, res) { dbPages.getPageList() .then(function(data) { - console.log(util.inspect(data)); - - res.render('pages', {data:data}); + res.render('pages', {data: data}); }).catch((err)=> { - console.error(err); - res.status(401).end(); - }); - }); + console.error(err); + res.status(401).end(); + }); + }); pagesRouter.post('/', function(req, res) { - console.log(util.inspect(req.body.data)); - dbPages.addNewPage(req.body.data) .then(function(data) { @@ -88,7 +81,6 @@ module.exports = function(app) { data: data }; - console.log('Finalising...'); res.status(200).send(response); eventHandler.emit('renderPage', data.attributes); @@ -100,7 +92,6 @@ module.exports = function(app) { }); pagesRouter.patch('/', function(req, res) { - console.log(util.inspect(req.body.data)); dbPages.addNewPage(req.body.data) .then(function(data) { @@ -108,8 +99,6 @@ module.exports = function(app) { let response = { data: data }; - - console.log('Finalising...'); res.status(200).send(response); eventHandler.emit('renderPage', data.attributes); @@ -128,29 +117,8 @@ module.exports = function(app) { }); }); - pagesRouter.put('/:id', function(req, res) { - res.send({ - pages: { - id: req.params.id - } - }); - }); - - pagesRouter.delete('/:id', function(req, res) { - res.status(204).end(); - }); - - // The POST and PUT call will not contain a request body - // because the body-parser is not included by default. - // To use req.body, run: - - // Npm install --save-dev body-parser app.use('/api/pages', require('body-parser').json({type: 'application/vnd.api+json'})); - // After installing, you need to `use` the body-parser for - // this mock uncommenting the following line: - // - //App.use('/api/pages', require('body-parser').json()); app.use('/api/pages', pagesRouter); }; diff --git a/server/app/profiles.js b/server/app/profiles.js index cc371c6..474472b 100644 --- a/server/app/profiles.js +++ b/server/app/profiles.js @@ -36,31 +36,10 @@ module.exports = function(app) { res.status(200).send(response); }) .catch(function(e) { - 'use strict'; console.error(e); res.status(401).end(); }); - }; - }); - - profilesRouter.post('/', function(req, res) { - res.status(201).end(); - }); - - profilesRouter.get('/:id', function(req, res) { - res.send({ - profiles: { - id: req.params.id - } - }); - }); - - profilesRouter.put('/:id', function(req, res) { - res.send({ - profiles: { - id: req.params.id - } - }); + } }); profilesRouter.patch('/:id', function(req, res) { @@ -85,7 +64,6 @@ module.exports = function(app) { res.status(200).send(response); }) .catch(function(err) { - 'use strict'; console.error(err); res.status(401).end(); }); @@ -96,16 +74,6 @@ module.exports = function(app) { res.status(204).end(); }); - // The POST and PUT call will not contain a request body - // because the body-parser is not included by default. - // To use req.body, run: - - // Npm install --save-dev body-parser - - // After installing, you need to `use` the body-parser for - // this mock uncommenting the following line: - // - //App.use('/api/profiles', require('body-parser').json()); app.use('/api/profiles', require('body-parser').json()); app.use('/api/profiles', require('body-parser').json({type: 'application/vnd.api+json'})); diff --git a/server/app/token.js b/server/app/token.js index 443f6a3..5388e95 100644 --- a/server/app/token.js +++ b/server/app/token.js @@ -16,7 +16,6 @@ module.exports = function(app) { }); tokenRouter.post('/', function(req, res) { - logger.debug('POST'); if (req.body.hasOwnProperty('grant_type')) { if (req.body.grant_type === 'password') { dbAccounts.findAccount({ @@ -53,38 +52,7 @@ module.exports = function(app) { }); - tokenRouter.get('/:id', function(req, res) { - res.send({ - token: { - id: req.params.id - } - }); - }); - - tokenRouter.put('/:id', function(req, res) { - res.send({ - token: { - id: req.params.id - } - }); - }); - - tokenRouter.delete('/:id', function(req, res) { - res.status(204).end(); - }); - - // The POST and PUT call will not contain a request body - // because the body-parser is not included by default. - // To use req.body, run: - - // Npm install --save-dev body-parser - - // After installing, you need to `use` the body-parser for - // this mock uncommenting the following line: - // - //app.use('/token', require('body-parser').json()); - // app.use('/token', require('body-parser').text()); - app.use('/token', require('body-parser').urlencoded()); + app.use('/token', require('body-parser').urlencoded()); app.use('/token', tokenRouter); }; diff --git a/server/css/obrand.css b/server/css/obrand.css index de064e5..1fd9a5c 100644 --- a/server/css/obrand.css +++ b/server/css/obrand.css @@ -7,3 +7,9 @@ margin-left: auto; margin-right: auto; } + +#image.img { + max-width: 300px; + max-height: 300px; + + } diff --git a/server/units/db-accounts.js b/server/units/db-accounts.js index 0610fdb..8dc351e 100644 --- a/server/units/db-accounts.js +++ b/server/units/db-accounts.js @@ -48,8 +48,6 @@ module.exports = function(db) { return new Promise(function(resolve, reject) { db.one('select * from getAccountDetails($1);',[uid]) .then(function(d) { - console.log('+ sqlGetAccountDetails'); - console.log(d); return resolve(d); }) .catch((err)=> { @@ -119,7 +117,7 @@ module.exports = function(db) { return reject(mdErrors.error(1000)); } - if (mdValidator.Email(data.email) === false) { + if (mdValidator.Email(data.email) === false) { return reject(mdErrors.error(1001)); } else { // It should be possible to insert the user now. @@ -186,7 +184,7 @@ module.exports = function(db) { }); }; - //makeMemberOf(cid, uid) + //MakeMemberOf(cid, uid) module.makeMemberOf = function(cid, uid) { return new Promise((resolve, reject) => { this.sqlMakeMemberOf(cid, uid) diff --git a/server/units/db-pages.js b/server/units/db-pages.js index 93c812b..4e51371 100644 --- a/server/units/db-pages.js +++ b/server/units/db-pages.js @@ -17,20 +17,14 @@ module.exports = function(db) { var module = {}; module.getLatestAddedPage = function() { - console.log('+ getLatestAddedPage'); - //select '/export/' || pages.pid::text || '.html' as fullpath from pages order by id desc limit 1; return new Promise(function(resolve, reject) { db.oneOrNone( "select 'export/' || pages.pid::text || '.html' as fullpath from pages order by id desc limit 1;") .then((d) => { - console.log(d); - console.log('- getlastaddedpage'); return resolve(d); }) .catch((err)=> { - console.log('+getLatestAddedPage failed'); - console.log(err); return reject(err); }); }); @@ -46,8 +40,6 @@ module.exports = function(db) { return resolve(d); }) .catch((err)=> { - console.log('+getPageList failed'); - console.log(err); return reject(err); }); }); @@ -69,17 +61,12 @@ module.exports = function(db) { "type": "page", "attributes": attributeObj }; - - // { data: [ { "id": "56b7ecbc1ef21172377d6159", "type": "guest", "attributes": { "name":"Ray","message":"First ever guest post entry" } }, ... ] } - rArray.push(newObj); } return resolve(rArray); }) .catch((err)=> { - console.log('+getPageList failed'); - console.log(err); return reject(err); }); }); @@ -88,14 +75,10 @@ module.exports = function(db) { module.sqlInsertPage = function(data) { return new Promise(function(resolve, reject) { db.func('upsert_page', data) - .then((d)=> { - console.log(d); - console.log('+sqlInsertPage OK'); + .then(()=> { return resolve('ok'); }) .catch((err)=> { - console.log('+sqlInsertPage failed'); - console.log(err); return reject(err); }); }); @@ -106,7 +89,6 @@ module.exports = function(db) { return new Promise((resolve, reject) => { let _data, _jsonData; - console.log(data); _data = $U.cloneTrim(data.attributes); if (typeof _data.pid === 'undefined' || _data.pid === null) { @@ -136,16 +118,12 @@ module.exports = function(db) { JSON.stringify(_jsonData) ]; - console.log(sqlData); this.sqlInsertPage(sqlData) - .then(function(d) { - console.log('Inserted'); - console.log(d); + .then(function() { data.attributes = _data; return resolve(data); }) .catch(function(err) { - console.log('Failed to insert'); return reject(err); }); diff --git a/server/units/md-errors.js b/server/units/md-errors.js index c66a017..b0efbc6 100644 --- a/server/units/md-errors.js +++ b/server/units/md-errors.js @@ -26,8 +26,7 @@ var MDERRORS = new function() { }; this.error = function(code) { - var estring = ''; - estring = errors[code].name + ': ' + errors[code].title + '\nCode: ' + code + '\n'; + var estring = errors[code].name + ': ' + errors[code].title + '\nCode: ' + code + '\n'; logger.error(estring);