Reimport proper files for the todo application
4 files deleted
9 files added
1 files modified
17 files renamed
| | |
| | | FROM registry.access.redhat.com/ubi8:8.0 |
| | | FROM ubi7/ubi:7.7 |
| | | |
| | | LABEL version="1.0" \ |
| | | description="To Do List application front-end" \ |
| | | creationDate="2017-12-25" \ |
| | | updatedDate="2019-11-28" |
| | | MAINTAINER username <username@example.com> |
| | | |
| | | ENV BACKEND_HOST=localhost:8081 |
| | | ENV NODEJS_VERSION=8.0 \ |
| | | HOME=/opt/app-root/src |
| | | |
| | | RUN yum install -y --disableplugin=subscription-manager --nodocs \ |
| | | nginx nginx-mod-http-perl \ |
| | | && yum clean all |
| | | RUN yum install -y --setopt=tsflags=nodocs rh-nodejs8 make && \ |
| | | yum clean all -y && \ |
| | | mkdir -p /opt/app-root && \ |
| | | groupadd -r appuser -f -g 1001 && \ |
| | | useradd -u 1001 -r -g appuser -m -d ${HOME} -s /sbin/nologin \ |
| | | -c "Application User" appuser && \ |
| | | chown -R appuser:appuser /opt/app-root && \ |
| | | chmod -R 755 /opt/app-root |
| | | |
| | | COPY nginx.conf /etc/nginx/ |
| | | ADD ./enable-rh-nodejs8.sh /etc/profile.d/ |
| | | |
| | | RUN touch /run/nginx.pid \ |
| | | && chgrp -R nginx /var/log/nginx /run/nginx.pid \ |
| | | && chmod -R g+rwx /var/log/nginx /run/nginx.pid |
| | | COPY run.sh build ${HOME}/ |
| | | WORKDIR ${HOME} |
| | | RUN scl enable rh-nodejs8 'npm install' |
| | | |
| | | COPY src/ /usr/share/nginx/html |
| | | EXPOSE 8080 |
| | | USER 1001 |
| | | |
| | | EXPOSE 8080 |
| | | |
| | | USER nginx |
| | | |
| | | CMD nginx -g "daemon off;" |
| | | CMD ["scl","enable","rh-nodejs8","./run.sh"] |
New file |
| | |
| | | #!/bin/bash |
| | | |
| | | echo "Preparing build folder" |
| | | rm -fr build |
| | | mkdir -p build |
| | | cp -ap nodejs-source/* build |
| | | rm build/*.sh |
| | | chmod -R a+rwX build |
| | | |
| | | podman build --layers=false -t do280/todo-single . |
New file |
| | |
| | | #!/bin/bash |
| | | source /opt/rh/rh-nodejs8/enable |
| | | export X_SCLS="`scl enable rh-nodejs8 'echo $X_SCLS'`" |
New file |
| | |
| | | # DO276 JavaScript/Node.js To Do List App |
| | | |
| | | Based on Restify 4.0 and Sequelize 3.14. Tested on Node.js 0.10 from SCL with |
| | | Mariadb 5.5. |
| | | |
| | | Do `npm install` do download dependencies. |
| | | |
| | | Run as `node app.js` |
| | | |
| | | * Don't do pagination yet. |
| | | |
| | | * Database connection parameters hardcoded (as a novice developer would usually do). |
| | | |
| | | * There is a lot of boiler plate code in the controller and the model. There should |
| | | be a way to have more centralized error handling. |
| | | |
| | | * Access app as http://localhost:30080/todo |
New file |
| | |
| | | var restify = require('restify'); |
| | | |
| | | var controller = require('./controllers/items'); |
| | | |
| | | var db = require('./models/db'); |
| | | var model = require('./models/items'); |
| | | |
| | | model.connect(db.params, function(err) { |
| | | if (err) throw err; |
| | | }); |
| | | |
| | | var server = restify.createServer() |
| | | .use(restify.plugins.fullResponse()) |
| | | .use(restify.plugins.queryParser()) |
| | | .use(restify.plugins.bodyParser()); |
| | | |
| | | controller.context(server, '/todo/api', model); |
| | | |
| | | server.get({ |
| | | path: '/todo/api/items/:id' |
| | | }, controller.read); |
| | | |
| | | |
| | | server.get({ |
| | | path: '/todo/api/items' |
| | | }, controller.list); |
| | | |
| | | server.post({ |
| | | path: '/todo/api/items' |
| | | }, controller.save); |
| | | |
| | | server.del({ |
| | | path: '/todo/api/items/:id' |
| | | }, controller.destroy); |
| | | |
| | | |
| | | server.get({ |
| | | path: '/todo/*', |
| | | name: 'todoapi' |
| | | }, restify.plugins.serveStatic({ |
| | | 'directory': __dirname, |
| | | 'default': 'index.html' |
| | | })); |
| | | |
| | | var port = process.env.APP_PORT || 8080; |
| | | server.listen(port, function (err) { |
| | | if (err) |
| | | console.error(err); |
| | | else |
| | | console.log('App is ready at : ' + port); |
| | | }); |
| | | |
| | | if (process.env.environment == 'production') |
| | | process.on('uncaughtException', function (err) { |
| | | console.error(JSON.parse(JSON.stringify(err, ['stack', 'message', 'inner'], 2))) |
| | | }); |
New file |
| | |
| | | #!/bin/bash |
| | | |
| | | npm install |
File was renamed from todo-single/src/controllers/items.js |
| | |
| | | if (path) |
| | | context = path + context; |
| | | |
| | | server.get(context + '/', this.list); |
| | | server.get(context + '/:id', this.read); |
| | | server.get(context + '-count', this.count); |
| | | server.post(context + '/', this.save); |
| | | server.del(context + '/:id', this.destroy); |
| | | // server.get(context + '/', this.list); |
| | | // server.get(context + '/:id', this.read); |
| | | // server.post(context + '/', this.save); |
| | | // server.del(context + '/:id', this.destroy); |
| | | |
| | | model = itemsModel; |
| | | }; |
| | |
| | | |
| | | model.listAll(page_no, sortField, sortDirection, function(err, items) { |
| | | if (err) { |
| | | res.send(err); |
| | | next(err); |
| | | } |
| | | else { |
| | | if (items) { |
| | | model.countAll(function(err, n) { |
| | | if (err) { |
| | | res.send(err); |
| | | next(err); |
| | | } |
| | | else { |
| | | if (n) { |
| | |
| | | res.json(page); |
| | | next(); |
| | | } |
| | | else { |
| | | next(new Error("Can't count items")); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | else { |
| | | res.send(err); |
| | | next(new Error("Can't retrieve items")); |
| | | } |
| | | } |
| | | }) |
| | |
| | | var key = req.params.id; |
| | | model.read(key, function(err, item) { |
| | | if (err) { |
| | | res.send(err); |
| | | next(err); |
| | | } |
| | | else { |
| | | if (item) { |
| | |
| | | next(); |
| | | } |
| | | else { |
| | | res.send(err); |
| | | next(new Error("Can't retrieve items")); |
| | | } |
| | | } |
| | | }) |
| | | }; |
| | | |
| | | |
| | | exports.count = function(req, res, next) { |
| | | model.countAll(function(err, n) { |
| | | if (err) { |
| | | res.send(err); |
| | | } |
| | | else { |
| | | var page = { |
| | | count: n |
| | | }; |
| | | res.json(page) |
| | | next(); |
| | | } |
| | | }) |
| | | }; |
| | | |
| | | |
| | | exports.save = function(req, res, next) { |
| | | if (req.params.id) { |
| | | model.update(req.params.id, req.params.description, req.params.done, function(err, item) { |
| | | if (req.body.id) { |
| | | model.update(req.body.id, req.body.description, req.body.done, function(err, item) { |
| | | if (err) { |
| | | res.send(err); |
| | | next(err); |
| | | } |
| | | else { |
| | | res.json(item); |
| | |
| | | }); |
| | | } |
| | | else { |
| | | model.create(req.params.description, req.params.done, function(err, item) { |
| | | model.create(req.body.description, req.body.done, function(err, item) { |
| | | if (err) { |
| | | res.send(err); |
| | | next(err); |
| | | } |
| | | else { |
| | | res.json(item); |
| | |
| | | if (req.params.id) { |
| | | model.destroy(req.params.id, function(err, item) { |
| | | if (err) { |
| | | res.send(err); |
| | | next(err); |
| | | } |
| | | else { |
| | | //XXX jee_api does NOT return item on delete |
| | | res.json(item); |
| | | } |
| | | }); |
New file |
| | |
| | | |
| | | module.exports.params = { |
| | | dbname: process.env.MYSQL_ENV_MYSQL_DATABASE, |
| | | username: process.env.MYSQL_ENV_MYSQL_USER, |
| | | password: process.env.MYSQL_ENV_MYSQL_PASSWORD, |
| | | params: { |
| | | host: process.env.MYSQL_SERVICE_HOST, |
| | | port: process.env.MYSQL_SERVICE_PORT, |
| | | dialect: 'mysql' |
| | | } |
| | | }; |
File was renamed from todo-single/src/models/items.js |
| | |
| | | timestamps: false, |
| | | freezeTableName: true |
| | | }); |
| | | |
| | | if (process.env.DATABASE_INIT == 'true') { |
| | | Item.sync({ force: true }).then(function() { |
| | | callback(); |
| | | }).catch(function(err) { |
| | | callback(err); |
| | | }); |
| | | } |
| | | // drop and create tables, better done globally |
| | | /* |
| | | Item.sync({ force: true }).then(function() { |
| | | callback(); |
| | | }).error(function(err) { |
| | | callback(err); |
| | | }); |
| | | */ |
| | | } |
| | | |
| | | exports.disconnect = function(callback) { |
| | |
| | | done: (done) ? true : false |
| | | }).then(function(item) { |
| | | callback(null, item); |
| | | }).catch(function(err) { |
| | | }).error(function(err) { |
| | | callback(err); |
| | | }); |
| | | } |
| | | |
| | | exports.update = function(key, description, done, callback) { |
| | | Item.find({ where:{ id: key } }).then(function(item) { |
| | | Item.findOne({ where:{ id: key } }).then(function(item) { |
| | | if (!item) { |
| | | callback(new Error("Nothing found for key " + key)); |
| | | } |
| | | else { |
| | | item.updateAttributes({ |
| | | item.update({ |
| | | description: description, |
| | | done: (done) ? true : false |
| | | }).then(function() { |
| | |
| | | callback(err); |
| | | }); |
| | | } |
| | | }).catch(function(err) { |
| | | }).error(function(err) { |
| | | callback(err); |
| | | }); |
| | | } |
| | | |
| | | |
| | | exports.read = function(key, callback) { |
| | | Item.find({ where:{ id: key } }).then(function(item) { |
| | | Item.findOne({ where:{ id: key } }).then(function(item) { |
| | | if (!item) { |
| | | callback(new Error("Nothing found for key " + key)); |
| | | } |
| | |
| | | done: item.done |
| | | }); |
| | | } |
| | | }).catch(function(err) { |
| | | }).error(function(err) { |
| | | callback(err); |
| | | }); |
| | | } |
| | | |
| | | exports.destroy = function(key, callback) { |
| | | Item.find({ where:{ id: key } }).then(function(item) { |
| | | Item.findOne({ where:{ id: key } }).then(function(item) { |
| | | if (!item) { |
| | | callback(new Error("Nothing found for " + key)); |
| | | } |
| | |
| | | callback(err); |
| | | }); |
| | | } |
| | | }).catch(function(err) { |
| | | }).error(function(err) { |
| | | callback(err); |
| | | }); |
| | | } |
| | | |
| | | exports.countAll = function(callback) { |
| | | Item.findAll({ |
| | | attributes: [[Sequelize.fn('COUNT', Sequelize.col('id')), 'no_items']] |
| | | }).then(function(n) { |
| | | Item.findAll({ attributes: [[Sequelize.fn('COUNT', Sequelize.col('id')), 'no_items']] } ).then(function(n) { |
| | | callback(null, n[0].get('no_items')); |
| | | }).catch(function(err) { |
| | | }).error(function(err) { |
| | | callback(err); |
| | | }); |
| | | //callback(null, 100); |
| | | } |
| | | |
| | | exports.listAll = function(page, sortField, sortDirection, callback) { |
| | |
| | | id: item.id, description: item.description, done: item.done }); |
| | | }); |
| | | callback(null, theitems); |
| | | }).catch(function(err) { |
| | | }).error(function(err) { |
| | | callback(err); |
| | | }); |
| | | } |
New file |
| | |
| | | { |
| | | "name": "todo", |
| | | "version": "0.0.1", |
| | | "private": true, |
| | | "dependencies": { |
| | | "restify": "8.4.0", |
| | | "sequelize": "5.21.1", |
| | | "mysql2": "2.0.0" |
| | | } |
| | | } |
New file |
| | |
| | | #!/bin/bash |
| | | |
| | | node app.js |
| | | |
New file |
| | |
| | | #!/bin/sh |
| | | |
| | | node app.js |
| | | |