From 987562a8169061322f658e9d8903ac97198e0305 Mon Sep 17 00:00:00 2001 From: Morgan Tatum Shaw Date: Fri, 27 Sep 2019 21:44:32 -0700 Subject: [PATCH 1/2] server up --- .eslintignore | 6 ++ .eslintrc.json | 25 ++++++++ .gitignore | 109 ++++++++++++++++++++++++++++++++++ .travis.yml | 8 +++ __test__/pol.test.js | 15 +++++ docs/config/jsdoc.config.json | 10 ++++ index.js | 34 +++++++++++ package.json | 23 +++++++ pol.js | 18 ++++++ 9 files changed, 248 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc.json create mode 100755 .gitignore create mode 100644 .travis.yml create mode 100644 __test__/pol.test.js create mode 100755 docs/config/jsdoc.config.json create mode 100644 index.js create mode 100644 package.json create mode 100644 pol.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..5c0378e --- /dev/null +++ b/.eslintignore @@ -0,0 +1,6 @@ +**/node_modules/* +**/docs/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..7018e1b --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,25 @@ +{ + "env": { + "browser": true, + "node": true, + "commonjs": true, + "jest": true, + "es6": true + }, + "globals": { + "fail":true + }, + "extends": "eslint:recommended", + "parserOptions": { + "sourceType": "module", + "ecmaVersion": 2018 + }, + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": ["error", "single", { "allowTemplateLiterals": true }], + "comma-dangle": ["error", "always-multiline"], + "semi": [ "error", "always" ], + "no-unused-vars": [1, {"vars": "local", "args": "none"}] + } +} diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..28b9480 --- /dev/null +++ b/.gitignore @@ -0,0 +1,109 @@ + +# Created by https://www.gitignore.io/api/vim,osx,linux,node +db +temp +.env +*.env +package-lock.json +aws.yml + +**/docs/* +!**/docs/config/ +!**/docs/swagger.json + +# ignore the webstorm ide dir +.idea/ + +### Vim ### +# swap +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +# session +Session.vim +# temporary +.netrwhist +*~ +# auto-generated tag files +tags + + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + + +### Node ### +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..775c48d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: node_js +node_js: + - "stable" + +script: + - npm run lint + - npm test + diff --git a/__test__/pol.test.js b/__test__/pol.test.js new file mode 100644 index 0000000..9fc9bb9 --- /dev/null +++ b/__test__/pol.test.js @@ -0,0 +1,15 @@ +'use strict'; + +let pol = require('../pol.js'); + +describe('proof of life', () => { + + it('lives by default', () => { + expect(pol.isAlive()).toBeTruthy(); + }); + + it('dies with a param', () => { + expect(pol.isAlive('x')).toBeFalsy(); + }); + +}); diff --git a/docs/config/jsdoc.config.json b/docs/config/jsdoc.config.json new file mode 100755 index 0000000..ceaf75e --- /dev/null +++ b/docs/config/jsdoc.config.json @@ -0,0 +1,10 @@ +{ + "source": { + "include" : ["./"], + "exclude" : ["./node_modules"] + }, + "opts": { + "destination": "./docs/", + "recurse": true + } +} diff --git a/index.js b/index.js new file mode 100644 index 0000000..459969d --- /dev/null +++ b/index.js @@ -0,0 +1,34 @@ +'use strict'; + +/** + * Simple Server + * @module index + */ + + +const express = require('express'); + +const pol = require('./pol.js'); + +const app = express(); + +app.use('/docs', express.static('./docs')); + +/** + * / Request Handler (All Routes) + * @param req + * @param res + */ + +app.get('/', requestHandler); + +function requestHandler(req,res) { + res.setHeader('Content-Type', 'text/html'); + res.statusCode = 200; + let isItAlive = pol.isAlive(req.query.dead).toString(); + res.write( isItAlive ); + res.end(); +} + +app.listen(process.env.PORT, () => console.log('server up') ); + diff --git a/package.json b/package.json new file mode 100644 index 0000000..7349e96 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "401-js-proof-of-life", + "version": "1.0.0", + "description": "Proof of Life", + "main": "index.js", + "scripts": { + "start": "node index.js", + "lint": "eslint '**/*.js'", + "test": "jest --verbose --coverage", + "test-watch": "jest --watchAll --verbose --coverage", + "jsdoc": "jsdoc -c ./docs/config/jsdoc.config.json" + }, + "author": "John Cokos", + "license": "MIT", + "devDependencies": { + "eslint": "^6.1.0", + "eslint-plugin-react": "^7.14.3", + "jest": "^24.8.0" + }, + "dependencies": { + "express": "^4.17.1" + } +} diff --git a/pol.js b/pol.js new file mode 100644 index 0000000..25cd42c --- /dev/null +++ b/pol.js @@ -0,0 +1,18 @@ +'use strict'; + +/** + * Proof Of Life + * @module pol + */ + +/** + * Proof of life - will return a boolean value + * @param dead + * @returns {boolean} + * @function isAlive + */ +const isAlive = function(dead = false) { + return !(dead); +}; + +module.exports = {isAlive}; From 80f756e8630d2a607293bc0589142ada567cc35b Mon Sep 17 00:00:00 2001 From: Morgan Tatum Shaw Date: Fri, 27 Sep 2019 22:01:49 -0700 Subject: [PATCH 2/2] updated readme --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ce46b0f..4107e17 100644 --- a/README.md +++ b/README.md @@ -1 +1,42 @@ -# lab00 \ No newline at end of file +# LAB - 00 + +## POL Server + +### Author: Morgan Shaw + +### Links and Resources +* [submission PR] https://github.com/morgan-401-advanced-javascript/lab00/pull/1 +* [travis]https://travis-ci.com/morgan-401-advanced-javascript/lab00 +* [front-end](http://xyz.com) https://lab00morgan401.herokuapp.com + +#### Documentation +* [jsdoc] Unable to get jsdocs to work + +### Modules +#### `modulename.js` +##### Exported Values and Methods + +###### `foo(thing) -> string` +Usage Notes or examples + +###### `bar(array) -> array` +Usage Notes or examples + +### Setup +#### `.env` requirements +* `PORT` - 3000 + +#### Running the app +* `npm start` +* Endpoint: `/foo/bar/` + * Returns a JSON object with abc in it. +* Endpoint: `/bing/zing/` + * Returns a JSON object with xyz in it. + +#### Tests +* How do you run tests? +* What assertions were made? +* What assertions need to be / should be made? + +#### UML +Link to an image of the UML for your application and response to events