-
Notifications
You must be signed in to change notification settings - Fork 12
scaffolding #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jmpaik
wants to merge
11
commits into
codefellows-seattle-javascript-401d12:master
Choose a base branch
from
jmpaik:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
scaffolding #1
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ba88e43
scaffolding
jmpaik 15da0e2
add constants
jmpaik 1158ae2
create custom body parsing module
jmpaik ba2328e
renaming structure titles for learning purpose
jmpaik d56afdb
logic method GET
jmpaik 2c27e85
logic method POST
jmpaik 06ad0d0
start server
jmpaik 5918be3
debugging
jmpaik d76ecac
added READ ME
jmpaik 022a006
debugged complete
jmpaik d1aa286
minor edit
jmpaik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "rules": { | ||
| "no-console": "off", | ||
| "indent": [ "error", 2 ], | ||
| "quotes": [ "error", "single" ], | ||
| "semi": ["error", "always"], | ||
| "linebreak-style": [ "error", "unix" ] | ||
| }, | ||
| "env": { | ||
| "es6": true, | ||
| "node": true, | ||
| "mocha": true, | ||
| "jasmine": true | ||
| }, | ||
| "ecmaFeatures": { | ||
| "modules": true, | ||
| "experimentalObjectRestSpread": true, | ||
| "impliedStrict": true | ||
| }, | ||
| "extends": "eslint:recommended" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| Skip to content | ||
| This repository | ||
| Search | ||
| Pull requests | ||
| Issues | ||
| Gist | ||
| @jmpaik | ||
| Watch 5 | ||
| Star 1 | ||
| Fork 8 codefellows/seattle-javascript-401d12 | ||
| Code Issues 0 Pull requests 0 Projects 0 Wiki Pulse Graphs | ||
| Branch: master Find file Copy pathseattle-javascript-401d12/06-tcp_servers/demo/chat-server/.gitignore | ||
| 78ba337 a day ago | ||
| @bnates bnates added lecture 06 | ||
| 1 contributor | ||
| RawBlameHistory | ||
| 128 lines (94 sloc) 1.85 KB | ||
| # Created by https://www.gitignore.io/api/node,vim,macos,linux,windows | ||
|
|
||
| node_modules/ | ||
|
|
||
| ### Node ### | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
|
|
||
| # Runtime data | ||
| pids | ||
| *.pid | ||
| *.seed | ||
| *.pid.lock | ||
|
|
||
| # 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 eslint cache | ||
| .eslintcache | ||
|
|
||
| # Optional REPL history | ||
| .node_repl_history | ||
|
|
||
| # Output of 'npm pack' | ||
| *.tgz | ||
|
|
||
| # Yarn Integrity file | ||
| .yarn-integrity | ||
|
|
||
|
|
||
|
|
||
| ### Vim ### | ||
| # swap | ||
| [._]*.s[a-w][a-z] | ||
| [._]s[a-w][a-z] | ||
| # session | ||
| Session.vim | ||
| # temporary | ||
| .netrwhist | ||
| *~ | ||
| # auto-generated tag files | ||
| tags | ||
|
|
||
|
|
||
| ### macOS ### | ||
| *.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-* | ||
|
|
||
| # .nfs files are created when an open file is removed but is still being accessed | ||
| .nfs* | ||
|
|
||
|
|
||
| ### Windows ### | ||
| # Windows image file caches | ||
| Thumbs.db | ||
| ehthumbs.db | ||
|
|
||
| # Folder config file | ||
| Desktop.ini | ||
|
|
||
| # Recycle Bin used on file shares | ||
| $RECYCLE.BIN/ | ||
|
|
||
| # Windows Installer files | ||
| *.cab | ||
| *.msi | ||
| *.msm | ||
| *.msp | ||
|
|
||
| # Windows shortcuts | ||
| *.lnk | ||
| Contact GitHub API Training Shop Blog About | ||
| © 2016 GitHub, Inc. Terms Privacy Security Status Help |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Cowsay API | ||
| ============= | ||
|
|
||
| > | ||
|
|
||
| ## Getting Started | ||
|
|
||
|
|
||
| ### Prereqs | ||
|
|
||
| - dependencies: | ||
| cowsay: ^1.1.9 --> npm install -S cowsay | ||
|
|
||
|
|
||
| ## Running | ||
|
|
||
| In root server, type in the command **"node server.js"** in first terminal pane. | ||
|
|
||
| In Second Terminal Pane : | ||
|
|
||
| - For Get Request: | ||
| ``` http localhost:3000/ : will respond with Hello From The Server``` | ||
| ``` http localhost:3000/cowsay text=='some text' : will respond with cowsay``` | ||
|
|
||
| In Third Terminal Pane: | ||
| - For POST Request: | ||
| ``` we need a json file in root directory like: data.json with simple json string``` | ||
| ``` cat data.json | http post localhost:3000/cowsay : will show json data using cowsay``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| 'use strict'; | ||
|
|
||
| const gulp = require('gulp'); | ||
| const eslint = require('gulp-eslint'); | ||
| const mocha = require('gulp-mocha'); | ||
|
|
||
| gulp.task('test', function(){ | ||
| gulp.src('./test/*-test.js', {read: false}) | ||
| .pipe(mocha({reporter: 'spec'})); | ||
| }); | ||
|
|
||
| gulp.task('lint', function(){ | ||
| return gulp.src(['**/*.js','!node_modules/**']) | ||
| .pipe(eslint()) | ||
| .pipe(eslint.format()) | ||
| .pipe(eslint.failAfterError()); | ||
| }); | ||
|
|
||
| gulp.task('dev', function(){ | ||
| gulp.watch(['**/*.js','!node_modules/**'], ['lint', 'test']); | ||
| }); | ||
|
|
||
| gulp.task('default', ['dev']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = function(req, callback) { | ||
| req.body = ''; | ||
|
|
||
| req.on('data', function(data) { | ||
| req.body += data.toString(); | ||
| }); | ||
|
|
||
| req.on('end', function() { | ||
| try { | ||
| req.body = JSON.parse(req.body); | ||
| callback(null, req.body); | ||
| } catch (err) { | ||
| callback(err); | ||
| } | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "lab-jinho", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "main": "server.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "start": "node server.js" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "cowsay": "^1.1.9" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| 'use strict'; | ||
|
|
||
| //**DEPENDENCIES** | ||
| //node modules | ||
| const http = require('http'); | ||
| const url = require('url'); | ||
| const queryString = require('querystring'); | ||
| //npm modules | ||
| const cowsay = require('cowsay'); | ||
| //custom modules | ||
| const parseBody = require('./lib/parse-body.js'); | ||
| //environment variables | ||
| const PORT = process.env.PORT || 3000; | ||
|
|
||
| //**LOGIC** | ||
| const server = http.createServer(function(req, res) { | ||
| req.url = url.parse(req.url); | ||
| req.url.query = queryString.parse(req.url.query); | ||
|
|
||
| //Logic: Method: GET | ||
| if (req.method === 'GET') { | ||
| if(req.url.pathname === '/') { | ||
| res.writeHead( 200, {'Content-Type': 'text/plain'}); | ||
| res.write('Hello From The Server'); | ||
| res.end(); | ||
| } | ||
| if (req.url.pathname === '/cowsay'){ | ||
| if (req.url.query.text) { | ||
| res.writeHead(200); | ||
| res.write(cowsay.say({text:req.url.query.text})); | ||
| res.end(); | ||
| return; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'bad request' isn't being displayed in the cow, you could add wrap the following logic in an if that handles the 400 if req.url.query.text does not exist. |
||
| res.writeHead(400); | ||
| res.write(cowsay.say({text:'bad request'})); | ||
| res.end(); | ||
| } | ||
| } | ||
|
|
||
| //Logic: Method: POST | ||
| if (req.method === 'POST' && req.url.pathname === '/cowsay') { | ||
| parseBody(req, function(err){ | ||
| if (err) {console.error(err); | ||
| res.writeHead(400,{'Content-Type': 'text/plain'}); | ||
| res.write(cowsay.say({text:'bad request'})); | ||
| res.end(); | ||
| return; | ||
| } | ||
| if(req.body.text){ | ||
| res.writeHead(200,{'Content-Type': 'text/plain'}); | ||
| res.write(cowsay.say({text:req.body.text})); | ||
| res.end(); | ||
| return; | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| //**START SERVER** | ||
| server.listen(PORT, function() { | ||
| console.log('server up:', PORT); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job adding docs! Get in the practice of making them thorough as they will need to be more detailed for future assignments.