From 5745b0b58fc4e6244ec690a5aa7476f090d75ead Mon Sep 17 00:00:00 2001 From: Andrej Rasevic <andrej@rasevicengineering.com> Date: Sat, 19 Jan 2019 07:55:48 -0500 Subject: [PATCH] adding project3 skeleton cmsc388b --- .../projects/project3/Project3Description.md | 0 .../project3/contact-list-api/.gitignore | 3 + .../projects/project3/contact-list-api/app.js | 20 +++++ .../project3/contact-list-api/bin/www | 90 +++++++++++++++++++ .../project3/contact-list-api/package.json | 14 +++ .../project3/contact-list-api/routes/index.js | 9 ++ .../project3/contact-list-api/routes/users.js | 9 ++ 7 files changed, 145 insertions(+) create mode 100644 cmsc388b/projects/project3/Project3Description.md create mode 100644 cmsc388b/projects/project3/contact-list-api/.gitignore create mode 100644 cmsc388b/projects/project3/contact-list-api/app.js create mode 100755 cmsc388b/projects/project3/contact-list-api/bin/www create mode 100644 cmsc388b/projects/project3/contact-list-api/package.json create mode 100644 cmsc388b/projects/project3/contact-list-api/routes/index.js create mode 100644 cmsc388b/projects/project3/contact-list-api/routes/users.js diff --git a/cmsc388b/projects/project3/Project3Description.md b/cmsc388b/projects/project3/Project3Description.md new file mode 100644 index 0000000..e69de29 diff --git a/cmsc388b/projects/project3/contact-list-api/.gitignore b/cmsc388b/projects/project3/contact-list-api/.gitignore new file mode 100644 index 0000000..f0e19b7 --- /dev/null +++ b/cmsc388b/projects/project3/contact-list-api/.gitignore @@ -0,0 +1,3 @@ +.DS_STORE + +node_modules \ No newline at end of file diff --git a/cmsc388b/projects/project3/contact-list-api/app.js b/cmsc388b/projects/project3/contact-list-api/app.js new file mode 100644 index 0000000..d187f73 --- /dev/null +++ b/cmsc388b/projects/project3/contact-list-api/app.js @@ -0,0 +1,20 @@ +var express = require('express'); +var path = require('path'); +var cookieParser = require('cookie-parser'); +var logger = require('morgan'); + +var indexRouter = require('./routes/index'); +var usersRouter = require('./routes/users'); + +var app = express(); + +app.use(logger('dev')); +app.use(express.json()); +app.use(express.urlencoded({ extended: false })); +app.use(cookieParser()); +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/', indexRouter); +app.use('/users', usersRouter); + +module.exports = app; diff --git a/cmsc388b/projects/project3/contact-list-api/bin/www b/cmsc388b/projects/project3/contact-list-api/bin/www new file mode 100755 index 0000000..e5b4c46 --- /dev/null +++ b/cmsc388b/projects/project3/contact-list-api/bin/www @@ -0,0 +1,90 @@ +#!/usr/bin/env node + +/** + * Module dependencies. + */ + +var app = require('../app'); +var debug = require('debug')('contact-list-api:server'); +var http = require('http'); + +/** + * Get port from environment and store in Express. + */ + +var port = normalizePort(process.env.PORT || '3000'); +app.set('port', port); + +/** + * Create HTTP server. + */ + +var server = http.createServer(app); + +/** + * Listen on provided port, on all network interfaces. + */ + +server.listen(port); +server.on('error', onError); +server.on('listening', onListening); + +/** + * Normalize a port into a number, string, or false. + */ + +function normalizePort(val) { + var port = parseInt(val, 10); + + if (isNaN(port)) { + // named pipe + return val; + } + + if (port >= 0) { + // port number + return port; + } + + return false; +} + +/** + * Event listener for HTTP server "error" event. + */ + +function onError(error) { + if (error.syscall !== 'listen') { + throw error; + } + + var bind = typeof port === 'string' + ? 'Pipe ' + port + : 'Port ' + port; + + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': + console.error(bind + ' requires elevated privileges'); + process.exit(1); + break; + case 'EADDRINUSE': + console.error(bind + ' is already in use'); + process.exit(1); + break; + default: + throw error; + } +} + +/** + * Event listener for HTTP server "listening" event. + */ + +function onListening() { + var addr = server.address(); + var bind = typeof addr === 'string' + ? 'pipe ' + addr + : 'port ' + addr.port; + debug('Listening on ' + bind); +} diff --git a/cmsc388b/projects/project3/contact-list-api/package.json b/cmsc388b/projects/project3/contact-list-api/package.json new file mode 100644 index 0000000..81347dd --- /dev/null +++ b/cmsc388b/projects/project3/contact-list-api/package.json @@ -0,0 +1,14 @@ +{ + "name": "contact-list-api", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./bin/www" + }, + "dependencies": { + "cookie-parser": "~1.4.3", + "debug": "~2.6.9", + "express": "~4.16.0", + "morgan": "~1.9.0" + } +} diff --git a/cmsc388b/projects/project3/contact-list-api/routes/index.js b/cmsc388b/projects/project3/contact-list-api/routes/index.js new file mode 100644 index 0000000..ecca96a --- /dev/null +++ b/cmsc388b/projects/project3/contact-list-api/routes/index.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('index', { title: 'Express' }); +}); + +module.exports = router; diff --git a/cmsc388b/projects/project3/contact-list-api/routes/users.js b/cmsc388b/projects/project3/contact-list-api/routes/users.js new file mode 100644 index 0000000..623e430 --- /dev/null +++ b/cmsc388b/projects/project3/contact-list-api/routes/users.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET users listing. */ +router.get('/', function(req, res, next) { + res.send('respond with a resource'); +}); + +module.exports = router; -- GitLab