From b3c9ac3c7e6a19265b34a244fd48893d12169036 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 19:54:24 +0000 Subject: [PATCH 01/24] Setting up GitHub Classroom Feedback From da64f84b7fc69d566bd858d514a1462993de5bc0 Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 23 Apr 2022 13:23:27 -0400 Subject: [PATCH 02/24] initial --- package-lock.json | 887 ++++++++++++++++++++++++++++++++++++++++++++++ server.js | 30 ++ 2 files changed, 917 insertions(+) create mode 100644 package-lock.json create mode 100644 server.js diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..3e16ce2 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,887 @@ +{ + "name": "a03-sep0225", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "a03-sep0225", + "version": "1.0.0", + "license": "GPL-3.0-or-later", + "dependencies": { + "express": "^4.17.3", + "minimist": "^1.2.6" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" + }, + "node_modules/body-parser": { + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.2.tgz", + "integrity": "sha512-SAAwOxgoCKMGs9uUAUFHygfLAyaniaoun6I8mFY9pRAJL9+Kec34aU+oIjDhTycub1jozEfEwx1W1IuOYxVSFw==", + "dependencies": { + "bytes": "3.1.2", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "~1.1.2", + "http-errors": "1.8.1", + "iconv-lite": "0.4.24", + "on-finished": "~2.3.0", + "qs": "6.9.7", + "raw-body": "2.4.3", + "type-is": "~1.6.18" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", + "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "node_modules/encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.17.3", + "resolved": "https://registry.npmjs.org/express/-/express-4.17.3.tgz", + "integrity": "sha512-yuSQpz5I+Ch7gFrPCk4/c+dIBKlQUxtgwqzph132bsT6qhuzss6I8cLJQz7B3rFblzd6wtcI0ZbGltH/C4LjUg==", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "1.19.2", + "content-disposition": "0.5.4", + "content-type": "~1.0.4", + "cookie": "0.4.2", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "~1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.1.2", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "~2.3.0", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.7", + "qs": "6.9.7", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "0.17.2", + "serve-static": "1.14.2", + "setprototypeof": "1.2.0", + "statuses": "~1.5.0", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + } + }, + "node_modules/finalhandler": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", + "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "~2.3.0", + "parseurl": "~1.3.3", + "statuses": "~1.5.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/http-errors": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", + "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", + "dependencies": { + "depd": "~1.1.2", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/minimist": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-IhMFgUmuNpyRfxA90umL7ByLlgRXu6tIfKPpF5TmcfRLlLCckfP/g3IQmju6jjpu+Hh8rA+2p6A27ZSPOOHdKw==", + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.3.tgz", + "integrity": "sha512-UlTNLIcu0uzb4D2f4WltY6cVjLi+/jEN4lgEUj3E04tpMDpUlkBo/eSn6zou9hum2VMNpCCUone0O0WeJim07g==", + "dependencies": { + "bytes": "3.1.2", + "http-errors": "1.8.1", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "node_modules/send": { + "version": "0.17.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.17.2.tgz", + "integrity": "sha512-UJYB6wFSJE3G00nEivR5rgWp8c2xXvJ3OPWPhmuteU0IKj8nKbG3DrjiOmLwpnHGYWAVwA69zmTm++YG0Hmwww==", + "dependencies": { + "debug": "2.6.9", + "depd": "~1.1.2", + "destroy": "~1.0.4", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "1.8.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.3.0", + "range-parser": "~1.2.1", + "statuses": "~1.5.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/serve-static": { + "version": "1.14.2", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.2.tgz", + "integrity": "sha512-+TMNA9AFxUEGuC0z2mevogSnn9MXKb4fa7ngeRMJaaGv8vTwnIEkKi+QGvPt33HSnf8pRS+WGM0EbMtCJLKMBQ==", + "dependencies": { + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "0.17.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + }, + "node_modules/statuses": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", + "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=", + "engines": { + "node": ">= 0.8" + } + } + }, + "dependencies": { + "accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "requires": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + } + }, + "array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" + }, + "body-parser": { + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.2.tgz", + "integrity": "sha512-SAAwOxgoCKMGs9uUAUFHygfLAyaniaoun6I8mFY9pRAJL9+Kec34aU+oIjDhTycub1jozEfEwx1W1IuOYxVSFw==", + "requires": { + "bytes": "3.1.2", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "~1.1.2", + "http-errors": "1.8.1", + "iconv-lite": "0.4.24", + "on-finished": "~2.3.0", + "qs": "6.9.7", + "raw-body": "2.4.3", + "type-is": "~1.6.18" + } + }, + "bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==" + }, + "content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "requires": { + "safe-buffer": "5.2.1" + } + }, + "content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" + }, + "cookie": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", + "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==" + }, + "cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" + }, + "express": { + "version": "4.17.3", + "resolved": "https://registry.npmjs.org/express/-/express-4.17.3.tgz", + "integrity": "sha512-yuSQpz5I+Ch7gFrPCk4/c+dIBKlQUxtgwqzph132bsT6qhuzss6I8cLJQz7B3rFblzd6wtcI0ZbGltH/C4LjUg==", + "requires": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "1.19.2", + "content-disposition": "0.5.4", + "content-type": "~1.0.4", + "cookie": "0.4.2", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "~1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.1.2", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "~2.3.0", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.7", + "qs": "6.9.7", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "0.17.2", + "serve-static": "1.14.2", + "setprototypeof": "1.2.0", + "statuses": "~1.5.0", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + } + }, + "finalhandler": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", + "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", + "requires": { + "debug": "2.6.9", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "~2.3.0", + "parseurl": "~1.3.3", + "statuses": "~1.5.0", + "unpipe": "~1.0.0" + } + }, + "forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==" + }, + "fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" + }, + "http-errors": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", + "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", + "requires": { + "depd": "~1.1.2", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.1" + } + }, + "iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" + }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" + }, + "mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, + "minimist": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "requires": { + "ee-first": "1.1.1" + } + }, + "parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" + }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" + }, + "proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "requires": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + } + }, + "qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-IhMFgUmuNpyRfxA90umL7ByLlgRXu6tIfKPpF5TmcfRLlLCckfP/g3IQmju6jjpu+Hh8rA+2p6A27ZSPOOHdKw==" + }, + "range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" + }, + "raw-body": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.3.tgz", + "integrity": "sha512-UlTNLIcu0uzb4D2f4WltY6cVjLi+/jEN4lgEUj3E04tpMDpUlkBo/eSn6zou9hum2VMNpCCUone0O0WeJim07g==", + "requires": { + "bytes": "3.1.2", + "http-errors": "1.8.1", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + } + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "send": { + "version": "0.17.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.17.2.tgz", + "integrity": "sha512-UJYB6wFSJE3G00nEivR5rgWp8c2xXvJ3OPWPhmuteU0IKj8nKbG3DrjiOmLwpnHGYWAVwA69zmTm++YG0Hmwww==", + "requires": { + "debug": "2.6.9", + "depd": "~1.1.2", + "destroy": "~1.0.4", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "1.8.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.3.0", + "range-parser": "~1.2.1", + "statuses": "~1.5.0" + }, + "dependencies": { + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + } + } + }, + "serve-static": { + "version": "1.14.2", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.2.tgz", + "integrity": "sha512-+TMNA9AFxUEGuC0z2mevogSnn9MXKb4fa7ngeRMJaaGv8vTwnIEkKi+QGvPt33HSnf8pRS+WGM0EbMtCJLKMBQ==", + "requires": { + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "0.17.2" + } + }, + "setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + }, + "statuses": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", + "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" + }, + "toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" + }, + "type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "requires": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + } + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" + }, + "utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" + }, + "vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" + } + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..53bf73e --- /dev/null +++ b/server.js @@ -0,0 +1,30 @@ +import { coinFlip, coinFlips, countFlips, flipACoin } from "./modules/coin.mjs" +import { createRequire } from 'module' +const require = createRequire(import.meta.url) + +// Require Express.js +const express = require('express') +const app = express() + +const args = require('minimist')(process.argv.slice(2)) +args['port'] +const port = args.port || process.env.PORT || 5000 + +// Start an app server +const server = app.listen(port, () => { + console.log('App listening on port %PORT%'.replace('%PORT%', port)) +}); + +// Default response for any other request +app.use(function(req, res){ + res.status(404).send('404 NOT FOUND') +}); + +app.get('/app/', (req, res) => { + // Respond with status 200 + res.statusCode = 200; + // Respond with status message "OK" + res.statusMessage = 'OK'; + res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' }); + res.end(res.statusCode+ ' ' +res.statusMessage) +}); \ No newline at end of file From a4f50c070e79adad99e568b6e5cafef38f1f983f Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 23 Apr 2022 13:23:36 -0400 Subject: [PATCH 03/24] initial --- package.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..324b0e3 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "a03-sep0225", + "version": "1.0.0", + "description": "building an API", + "main": "server.js", + "scripts": { + "test": "node server.js --port=5555", + "start": "node server.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/comp426-2022-spring/a03-sep0225.git" + }, + "author": "Sarah Paschal", + "license": "GPL-3.0-or-later", + "bugs": { + "url": "https://github.com/comp426-2022-spring/a03-sep0225/issues" + }, + "homepage": "https://github.com/comp426-2022-spring/a03-sep0225#readme" +} From 500da5737cd61c1871702c14d5d6fb2eedc8b6ff Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Fri, 29 Apr 2022 00:58:29 +0000 Subject: [PATCH 04/24] Update GitHub Classroom Autograding --- .github/classroom/autograding.json | 48 ++++++++++++++++++------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/.github/classroom/autograding.json b/.github/classroom/autograding.json index 743ad02..1a99140 100644 --- a/.github/classroom/autograding.json +++ b/.github/classroom/autograding.json @@ -1,14 +1,14 @@ { "tests": [ { - "name": "Default /app/ endpoint", + "name": "Default /app/ endpoint", "setup": "npm install", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl -I http://localhost:${PORT}/app/ && sleep 5s", "input": "", "output": "HTTP\\/(1.1|2)\\s*200\\s*(OK)?", "comparison": "regex", "timeout": 10, - "points": 7143 + "points": 7500 }, { "name": "Nonexistent endpoint", @@ -18,87 +18,97 @@ "output": "HTTP\\/(1.1|2)\\s*404\\s*(Not Found)?", "comparison": "regex", "timeout": 10, - "points": 7143 + "points": 7500 }, { - "name": "Random coin flip endpoint /app/flip/", + "name": "Random coin flip endpoint &#47;app&#47;flip", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl http://localhost:${PORT}/app/flip/ && sleep 5s", "input": "", "output": "\\{\"flip\":\"(heads|tails)\"\\}", "comparison": "regex", "timeout": 10, - "points": 7143 + "points": 7500 }, { - "name": "Flip many coins endpoint /app/flips/:number/", + "name": "Flip many coins endpoint /app/flips/:number/", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; NUMBER=\"$(shuf -i 100-500 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl http://localhost:${PORT}/app/flips/${NUMBER}/ && sleep 5s", "input": "", "output": "\\{\"raw\":\\[\"(heads|tails)\",.*\\],\"summary\":\\{\"(heads|tails)\":[0-9]{1,3},\"(heads|tails)\":[0-9]{1,3}\\}\\}", "comparison": "regex", "timeout": 10, - "points": 7143 + "points": 7500 }, { - "name": "Header check /app/flip/", + "name": "Header check /app/flip/", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl -I http://localhost:${PORT}/app/flip/ && sleep 5s", "input": "", "output": "HTTP\\/(1.1|2)\\s*200\\s*(OK)?", "comparison": "regex", "timeout": 10, - "points": 7143 + "points": 7500 }, { - "name": "Header check /app/flips/:number/", + "name": "Header check /app/flips/:number/", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; NUMBER=\"$(shuf -i 100-500 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl -I http://localhost:${PORT}/app/flips/${NUMBER}/ && sleep 5s", "input": "", "output": "HTTP\\/(1.1|2)\\s*200\\s*(OK)?", "comparison": "regex", "timeout": 10, - "points": 7143 + "points": 7500 }, { - "name": "Call a flip heads at endpoint /app/flip/call/heads/", + "name": "Call a flip heads at endpoint /app/flip/call/heads/", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl http://localhost:${PORT}/app/flip/call/heads/ && sleep 5s", "input": "", "output": "\\{\"call\":\"heads\",\"flip\":\"(heads|tails)\",\"result\":\"(win|lose)\"\\}", "comparison": "regex", "timeout": 10, - "points": 7143 + "points": 7500 }, { - "name": "Call a flip tails at endpoint /app/flip/call/tails/", + "name": "Call a flip tails at endpoint /app/flip/call/tails/", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl http://localhost:${PORT}/app/flip/call/tails/ && sleep 5s", "input": "", "output": "\\{\"call\":\"tails\",\"flip\":\"(heads|tails)\",\"result\":\"(win|lose)\"\\}", "comparison": "regex", "timeout": 10, - "points": 7143 + "points": 7500 }, { - "name": "Header check /app/flip/call/heads/", + "name": "Header check /app/flip/call/heads/", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl -I http://localhost:${PORT}/app/flip/call/heads/ && sleep 5s", "input": "", "output": "HTTP\\/(1.1|2)\\s*200\\s*(OK)?", "comparison": "regex", "timeout": 10, - "points": 7143 + "points": 7500 }, { - "name": "Header check /app/flip/call/tails/", + "name": "Header check /app/flip/call/tails/", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl -I http://localhost:${PORT}/app/flip/call/tails/ && sleep 5s", "input": "", "output": "HTTP\\/(1.1|2)\\s*200\\s*(OK)?", "comparison": "regex", "timeout": 10, - "points": 7142 + "points": 7500 + }, + { + "name": "Node version", + "setup": "", + "run": "node -v", + "input": "", + "output": "", + "comparison": "included", + "timeout": 10, + "points": null } ] } \ No newline at end of file From cb1c78b285148814321bdf408b8b14a2bbaa9e7b Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Fri, 29 Apr 2022 00:58:29 +0000 Subject: [PATCH 05/24] Update GitHub Classroom Autograding Workflow From 7ff41b8506c7e62d2665654f3cbfcd1aa9ac7b12 Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 10:29:26 -0400 Subject: [PATCH 06/24] updated server.js --- server.js | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 53bf73e..e2390df 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,6 @@ -import { coinFlip, coinFlips, countFlips, flipACoin } from "./modules/coin.mjs" -import { createRequire } from 'module' -const require = createRequire(import.meta.url) +// import { coinFlip, coinFlips, countFlips, flipACoin } from "./modules/coin.mjs" +// import { createRequire } from 'module' +// const require = createRequire(import.meta.url) // Require Express.js const express = require('express') @@ -27,4 +27,126 @@ app.get('/app/', (req, res) => { res.statusMessage = 'OK'; res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' }); res.end(res.statusCode+ ' ' +res.statusMessage) -}); \ No newline at end of file +}); + +app.get('/app/flip/', (req, res) => { + let flip = coinFlip() + res.statusCode = 200; + res.json({ 'flip': flip }) +}) + +app.get('/app/flips/:number', (req, res) => { + let flips = coinFlips(req.params.number) + let total = countFlips(flips) + res.statusCode = 200 + res.json({ 'raw': flips, 'summary': total }) +}) + +app.get('/app/flip/call/heads', (req, res) => { + let heads = flipACoin('heads') + res.statusCode = 200 + res.json(heads) +}) + +app.get('/app/flip/call/tails', (req, res) => { + let tails = flipACoin('tails') + res.statusCode = 200 + res.json(tails) +}) + +/** Simple coin flip + * + * Write a function that accepts no parameters but returns either heads or tails at random. + * + * @param {*} + * @returns {string} + * + * example: coinFlip() + * returns: heads + * + */ + + function coinFlip() { + return Math.random() < 0.6 ? ("heads") : ("tails") + } + + /** Multiple coin flips + * + * Write a function that accepts one parameter (number of flips) and returns an array of + * resulting "heads" or "tails". + * + * @param {number} flips + * @returns {string[]} results + * + * example: coinFlips(10) + * returns: + * [ + 'heads', 'heads', + 'heads', 'tails', + 'heads', 'tails', + 'tails', 'heads', + 'tails', 'heads' + ] + */ + + function coinFlips(flips) { + const arr = []; + for (let i = 0; i < flips; i++) { + arr[i] = coinFlip(); + } + return arr; + } + + /** Count multiple flips + * + * Write a function that accepts an array consisting of "heads" or "tails" + * (e.g. the results of your `coinFlips()` function) and counts each, returning + * an object containing the number of each. + * + * example: conutFlips(['heads', 'heads','heads', 'tails','heads', 'tails','tails', 'heads','tails', 'heads']) + * { tails: 5, heads: 5 } + * + * @param {string[]} array + * @returns {{ heads: number, tails: number }} + */ + + function countFlips(array) { + let h_amt = 0; + let t_amt = 0; + for (let i = 0; i < array.length; i++) { + if (array[i] == "heads") { + h_amt += 1; + } else { + t_amt += 1; + } + } + if (h_amt == 0) { + return "{ tails: " + t_amt + " }"; + } + if (t_amt == 0) { + return "{ heads: " + h_amt + " }"; + } + return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; + } + + /** Flip a coin! + * + * Write a function that accepts one input parameter: a string either "heads" or "tails", flips a coin, and then records "win" or "lose". + * + * @param {string} call + * @returns {object} with keys that are the input param (heads or tails), a flip (heads or tails), and the result (win or lose). See below example. + * + * example: flipACoin('tails') + * returns: { call: 'tails', flip: 'heads', result: 'lose' } + */ + + function flipACoin(call) { + let flip = coinFlip(); + let result = ""; + if (call == flip) { + result = "win"; + } else { + result = "lose"; + } + return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; + } From fe3d415e993a6b8fd21cd69dd33465fb803a109b Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 10:36:19 -0400 Subject: [PATCH 07/24] updated server.js pt 2 --- server.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/server.js b/server.js index e2390df..98ae5ab 100644 --- a/server.js +++ b/server.js @@ -1,12 +1,10 @@ -// import { coinFlip, coinFlips, countFlips, flipACoin } from "./modules/coin.mjs" -// import { createRequire } from 'module' -// const require = createRequire(import.meta.url) - // Require Express.js const express = require('express') const app = express() -const args = require('minimist')(process.argv.slice(2)) +const min = require('minimist') +const args = min(process.argv.slice(2)) + args['port'] const port = args.port || process.env.PORT || 5000 @@ -15,11 +13,6 @@ const server = app.listen(port, () => { console.log('App listening on port %PORT%'.replace('%PORT%', port)) }); -// Default response for any other request -app.use(function(req, res){ - res.status(404).send('404 NOT FOUND') -}); - app.get('/app/', (req, res) => { // Respond with status 200 res.statusCode = 200; @@ -54,6 +47,11 @@ app.get('/app/flip/call/tails', (req, res) => { res.json(tails) }) +// Default response for any other request +app.use(function(req, res){ + res.status(404).send('404 NOT FOUND') +}); + /** Simple coin flip * * Write a function that accepts no parameters but returns either heads or tails at random. From 359bdc6e0cd68554a1f2575d3b2dd75d4edb4241 Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 10:43:32 -0400 Subject: [PATCH 08/24] added dependencies --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 324b0e3..b2656df 100644 --- a/package.json +++ b/package.json @@ -16,5 +16,9 @@ "bugs": { "url": "https://github.com/comp426-2022-spring/a03-sep0225/issues" }, - "homepage": "https://github.com/comp426-2022-spring/a03-sep0225#readme" + "homepage": "https://github.com/comp426-2022-spring/a03-sep0225#readme", + "dependencies": { + "express": "^4.18.1", + "minimist": "^1.2.6" + } } From 12cd6e3d164415428ebda16fa4e4c306483fd52c Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 11:52:46 -0400 Subject: [PATCH 09/24] ughhh --- package-lock.json | 412 +++++++++++++++++++++++++++++++--------------- package.json | 2 +- server.js | 17 +- 3 files changed, 291 insertions(+), 140 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3e16ce2..e2cba2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "GPL-3.0-or-later", "dependencies": { - "express": "^4.17.3", + "express": "^4.18.1", "minimist": "^1.2.6" } }, @@ -31,23 +31,26 @@ "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, "node_modules/body-parser": { - "version": "1.19.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.2.tgz", - "integrity": "sha512-SAAwOxgoCKMGs9uUAUFHygfLAyaniaoun6I8mFY9pRAJL9+Kec34aU+oIjDhTycub1jozEfEwx1W1IuOYxVSFw==", + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.0.tgz", + "integrity": "sha512-DfJ+q6EPcGKZD1QWUjSpqp+Q7bDQTsQIF4zfUAtZ6qk+H/3/QRhg9CEp39ss+/T2vw0+HaidC0ecJj/DRLIaKg==", "dependencies": { "bytes": "3.1.2", "content-type": "~1.0.4", "debug": "2.6.9", - "depd": "~1.1.2", - "http-errors": "1.8.1", + "depd": "2.0.0", + "destroy": "1.2.0", + "http-errors": "2.0.0", "iconv-lite": "0.4.24", - "on-finished": "~2.3.0", - "qs": "6.9.7", - "raw-body": "2.4.3", - "type-is": "~1.6.18" + "on-finished": "2.4.1", + "qs": "6.10.3", + "raw-body": "2.5.1", + "type-is": "~1.6.18", + "unpipe": "1.0.0" }, "engines": { - "node": ">= 0.8" + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" } }, "node_modules/bytes": { @@ -58,6 +61,18 @@ "node": ">= 0.8" } }, + "node_modules/call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "dependencies": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -78,9 +93,9 @@ } }, "node_modules/cookie": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", - "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", + "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", "engines": { "node": ">= 0.6" } @@ -99,17 +114,21 @@ } }, "node_modules/depd": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", "engines": { - "node": ">= 0.6" + "node": ">= 0.8" } }, "node_modules/destroy": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } }, "node_modules/ee-first": { "version": "1.1.1", @@ -138,37 +157,38 @@ } }, "node_modules/express": { - "version": "4.17.3", - "resolved": "https://registry.npmjs.org/express/-/express-4.17.3.tgz", - "integrity": "sha512-yuSQpz5I+Ch7gFrPCk4/c+dIBKlQUxtgwqzph132bsT6qhuzss6I8cLJQz7B3rFblzd6wtcI0ZbGltH/C4LjUg==", + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.18.1.tgz", + "integrity": "sha512-zZBcOX9TfehHQhtupq57OF8lFZ3UZi08Y97dwFCkD8p9d/d2Y3M+ykKcwaMDEL+4qyUolgBDX6AblpR3fL212Q==", "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.19.2", + "body-parser": "1.20.0", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.4.2", + "cookie": "0.5.0", "cookie-signature": "1.0.6", "debug": "2.6.9", - "depd": "~1.1.2", + "depd": "2.0.0", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "etag": "~1.8.1", - "finalhandler": "~1.1.2", + "finalhandler": "1.2.0", "fresh": "0.5.2", + "http-errors": "2.0.0", "merge-descriptors": "1.0.1", "methods": "~1.1.2", - "on-finished": "~2.3.0", + "on-finished": "2.4.1", "parseurl": "~1.3.3", "path-to-regexp": "0.1.7", "proxy-addr": "~2.0.7", - "qs": "6.9.7", + "qs": "6.10.3", "range-parser": "~1.2.1", "safe-buffer": "5.2.1", - "send": "0.17.2", - "serve-static": "1.14.2", + "send": "0.18.0", + "serve-static": "1.15.0", "setprototypeof": "1.2.0", - "statuses": "~1.5.0", + "statuses": "2.0.1", "type-is": "~1.6.18", "utils-merge": "1.0.1", "vary": "~1.1.2" @@ -178,16 +198,16 @@ } }, "node_modules/finalhandler": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", - "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", + "integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==", "dependencies": { "debug": "2.6.9", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", - "on-finished": "~2.3.0", + "on-finished": "2.4.1", "parseurl": "~1.3.3", - "statuses": "~1.5.0", + "statuses": "2.0.1", "unpipe": "~1.0.0" }, "engines": { @@ -210,19 +230,59 @@ "node": ">= 0.6" } }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "node_modules/get-intrinsic": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", + "integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==", + "dependencies": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/http-errors": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", - "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", "dependencies": { - "depd": "~1.1.2", + "depd": "2.0.0", "inherits": "2.0.4", "setprototypeof": "1.2.0", - "statuses": ">= 1.5.0 < 2", + "statuses": "2.0.1", "toidentifier": "1.0.1" }, "engines": { - "node": ">= 0.6" + "node": ">= 0.8" } }, "node_modules/iconv-lite": { @@ -318,10 +378,18 @@ "node": ">= 0.6" } }, + "node_modules/object-inspect": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.0.tgz", + "integrity": "sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/on-finished": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", "dependencies": { "ee-first": "1.1.1" }, @@ -355,9 +423,12 @@ } }, "node_modules/qs": { - "version": "6.9.7", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.7.tgz", - "integrity": "sha512-IhMFgUmuNpyRfxA90umL7ByLlgRXu6tIfKPpF5TmcfRLlLCckfP/g3IQmju6jjpu+Hh8rA+2p6A27ZSPOOHdKw==", + "version": "6.10.3", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.3.tgz", + "integrity": "sha512-wr7M2E0OFRfIfJZjKGieI8lBKb7fRCH4Fv5KNPEs7gJ8jadvotdsS08PzOKR7opXhZ/Xkjtt3WF9g38drmyRqQ==", + "dependencies": { + "side-channel": "^1.0.4" + }, "engines": { "node": ">=0.6" }, @@ -374,12 +445,12 @@ } }, "node_modules/raw-body": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.3.tgz", - "integrity": "sha512-UlTNLIcu0uzb4D2f4WltY6cVjLi+/jEN4lgEUj3E04tpMDpUlkBo/eSn6zou9hum2VMNpCCUone0O0WeJim07g==", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", + "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", "dependencies": { "bytes": "3.1.2", - "http-errors": "1.8.1", + "http-errors": "2.0.0", "iconv-lite": "0.4.24", "unpipe": "1.0.0" }, @@ -412,23 +483,23 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/send": { - "version": "0.17.2", - "resolved": "https://registry.npmjs.org/send/-/send-0.17.2.tgz", - "integrity": "sha512-UJYB6wFSJE3G00nEivR5rgWp8c2xXvJ3OPWPhmuteU0IKj8nKbG3DrjiOmLwpnHGYWAVwA69zmTm++YG0Hmwww==", + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", + "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", "dependencies": { "debug": "2.6.9", - "depd": "~1.1.2", - "destroy": "~1.0.4", + "depd": "2.0.0", + "destroy": "1.2.0", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "etag": "~1.8.1", "fresh": "0.5.2", - "http-errors": "1.8.1", + "http-errors": "2.0.0", "mime": "1.6.0", "ms": "2.1.3", - "on-finished": "~2.3.0", + "on-finished": "2.4.1", "range-parser": "~1.2.1", - "statuses": "~1.5.0" + "statuses": "2.0.1" }, "engines": { "node": ">= 0.8.0" @@ -440,14 +511,14 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, "node_modules/serve-static": { - "version": "1.14.2", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.2.tgz", - "integrity": "sha512-+TMNA9AFxUEGuC0z2mevogSnn9MXKb4fa7ngeRMJaaGv8vTwnIEkKi+QGvPt33HSnf8pRS+WGM0EbMtCJLKMBQ==", + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", + "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", "dependencies": { "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "parseurl": "~1.3.3", - "send": "0.17.2" + "send": "0.18.0" }, "engines": { "node": ">= 0.8.0" @@ -458,12 +529,25 @@ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, + "node_modules/side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dependencies": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/statuses": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", "engines": { - "node": ">= 0.6" + "node": ">= 0.8" } }, "node_modules/toidentifier": { @@ -527,20 +611,22 @@ "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, "body-parser": { - "version": "1.19.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.2.tgz", - "integrity": "sha512-SAAwOxgoCKMGs9uUAUFHygfLAyaniaoun6I8mFY9pRAJL9+Kec34aU+oIjDhTycub1jozEfEwx1W1IuOYxVSFw==", + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.0.tgz", + "integrity": "sha512-DfJ+q6EPcGKZD1QWUjSpqp+Q7bDQTsQIF4zfUAtZ6qk+H/3/QRhg9CEp39ss+/T2vw0+HaidC0ecJj/DRLIaKg==", "requires": { "bytes": "3.1.2", "content-type": "~1.0.4", "debug": "2.6.9", - "depd": "~1.1.2", - "http-errors": "1.8.1", + "depd": "2.0.0", + "destroy": "1.2.0", + "http-errors": "2.0.0", "iconv-lite": "0.4.24", - "on-finished": "~2.3.0", - "qs": "6.9.7", - "raw-body": "2.4.3", - "type-is": "~1.6.18" + "on-finished": "2.4.1", + "qs": "6.10.3", + "raw-body": "2.5.1", + "type-is": "~1.6.18", + "unpipe": "1.0.0" } }, "bytes": { @@ -548,6 +634,15 @@ "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==" }, + "call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "requires": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + } + }, "content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -562,9 +657,9 @@ "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" }, "cookie": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", - "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==" + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", + "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==" }, "cookie-signature": { "version": "1.0.6", @@ -580,14 +675,14 @@ } }, "depd": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==" }, "destroy": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==" }, "ee-first": { "version": "1.1.1", @@ -610,53 +705,54 @@ "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, "express": { - "version": "4.17.3", - "resolved": "https://registry.npmjs.org/express/-/express-4.17.3.tgz", - "integrity": "sha512-yuSQpz5I+Ch7gFrPCk4/c+dIBKlQUxtgwqzph132bsT6qhuzss6I8cLJQz7B3rFblzd6wtcI0ZbGltH/C4LjUg==", + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.18.1.tgz", + "integrity": "sha512-zZBcOX9TfehHQhtupq57OF8lFZ3UZi08Y97dwFCkD8p9d/d2Y3M+ykKcwaMDEL+4qyUolgBDX6AblpR3fL212Q==", "requires": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.19.2", + "body-parser": "1.20.0", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.4.2", + "cookie": "0.5.0", "cookie-signature": "1.0.6", "debug": "2.6.9", - "depd": "~1.1.2", + "depd": "2.0.0", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "etag": "~1.8.1", - "finalhandler": "~1.1.2", + "finalhandler": "1.2.0", "fresh": "0.5.2", + "http-errors": "2.0.0", "merge-descriptors": "1.0.1", "methods": "~1.1.2", - "on-finished": "~2.3.0", + "on-finished": "2.4.1", "parseurl": "~1.3.3", "path-to-regexp": "0.1.7", "proxy-addr": "~2.0.7", - "qs": "6.9.7", + "qs": "6.10.3", "range-parser": "~1.2.1", "safe-buffer": "5.2.1", - "send": "0.17.2", - "serve-static": "1.14.2", + "send": "0.18.0", + "serve-static": "1.15.0", "setprototypeof": "1.2.0", - "statuses": "~1.5.0", + "statuses": "2.0.1", "type-is": "~1.6.18", "utils-merge": "1.0.1", "vary": "~1.1.2" } }, "finalhandler": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", - "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", + "integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==", "requires": { "debug": "2.6.9", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", - "on-finished": "~2.3.0", + "on-finished": "2.4.1", "parseurl": "~1.3.3", - "statuses": "~1.5.0", + "statuses": "2.0.1", "unpipe": "~1.0.0" } }, @@ -670,15 +766,43 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "get-intrinsic": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", + "integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==", + "requires": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1" + } + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "requires": { + "function-bind": "^1.1.1" + } + }, + "has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" + }, "http-errors": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", - "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", "requires": { - "depd": "~1.1.2", + "depd": "2.0.0", "inherits": "2.0.4", "setprototypeof": "1.2.0", - "statuses": ">= 1.5.0 < 2", + "statuses": "2.0.1", "toidentifier": "1.0.1" } }, @@ -748,10 +872,15 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" }, + "object-inspect": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.0.tgz", + "integrity": "sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g==" + }, "on-finished": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", "requires": { "ee-first": "1.1.1" } @@ -776,9 +905,12 @@ } }, "qs": { - "version": "6.9.7", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.7.tgz", - "integrity": "sha512-IhMFgUmuNpyRfxA90umL7ByLlgRXu6tIfKPpF5TmcfRLlLCckfP/g3IQmju6jjpu+Hh8rA+2p6A27ZSPOOHdKw==" + "version": "6.10.3", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.3.tgz", + "integrity": "sha512-wr7M2E0OFRfIfJZjKGieI8lBKb7fRCH4Fv5KNPEs7gJ8jadvotdsS08PzOKR7opXhZ/Xkjtt3WF9g38drmyRqQ==", + "requires": { + "side-channel": "^1.0.4" + } }, "range-parser": { "version": "1.2.1", @@ -786,12 +918,12 @@ "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" }, "raw-body": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.3.tgz", - "integrity": "sha512-UlTNLIcu0uzb4D2f4WltY6cVjLi+/jEN4lgEUj3E04tpMDpUlkBo/eSn6zou9hum2VMNpCCUone0O0WeJim07g==", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", + "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", "requires": { "bytes": "3.1.2", - "http-errors": "1.8.1", + "http-errors": "2.0.0", "iconv-lite": "0.4.24", "unpipe": "1.0.0" } @@ -807,23 +939,23 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "send": { - "version": "0.17.2", - "resolved": "https://registry.npmjs.org/send/-/send-0.17.2.tgz", - "integrity": "sha512-UJYB6wFSJE3G00nEivR5rgWp8c2xXvJ3OPWPhmuteU0IKj8nKbG3DrjiOmLwpnHGYWAVwA69zmTm++YG0Hmwww==", + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", + "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", "requires": { "debug": "2.6.9", - "depd": "~1.1.2", - "destroy": "~1.0.4", + "depd": "2.0.0", + "destroy": "1.2.0", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "etag": "~1.8.1", "fresh": "0.5.2", - "http-errors": "1.8.1", + "http-errors": "2.0.0", "mime": "1.6.0", "ms": "2.1.3", - "on-finished": "~2.3.0", + "on-finished": "2.4.1", "range-parser": "~1.2.1", - "statuses": "~1.5.0" + "statuses": "2.0.1" }, "dependencies": { "ms": { @@ -834,14 +966,14 @@ } }, "serve-static": { - "version": "1.14.2", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.2.tgz", - "integrity": "sha512-+TMNA9AFxUEGuC0z2mevogSnn9MXKb4fa7ngeRMJaaGv8vTwnIEkKi+QGvPt33HSnf8pRS+WGM0EbMtCJLKMBQ==", + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", + "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", "requires": { "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "parseurl": "~1.3.3", - "send": "0.17.2" + "send": "0.18.0" } }, "setprototypeof": { @@ -849,10 +981,20 @@ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, + "side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "requires": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + } + }, "statuses": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" }, "toidentifier": { "version": "1.0.1", diff --git a/package.json b/package.json index b2656df..f7ba4f6 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,6 @@ "homepage": "https://github.com/comp426-2022-spring/a03-sep0225#readme", "dependencies": { "express": "^4.18.1", - "minimist": "^1.2.6" + "yargs": "^17.4.1" } } diff --git a/server.js b/server.js index 98ae5ab..3028467 100644 --- a/server.js +++ b/server.js @@ -2,11 +2,20 @@ const express = require('express') const app = express() -const min = require('minimist') -const args = min(process.argv.slice(2)) +//const min = require('minimist') +//const args = min(process.argv.slice(2)) -args['port'] -const port = args.port || process.env.PORT || 5000 +//args['port'] +//const port = args.port || process.env.PORT || 5000 + +const args = require('yargs').argv +let port + +if (typeof args.port === "undefined") { + port = 5000; +} else { + port = args.port +} // Start an app server const server = app.listen(port, () => { From c6b9679efef2fb000641c35abda63a3c3617544b Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 12:06:32 -0400 Subject: [PATCH 10/24] what the heck --- package.json | 2 +- server.js | 17 ++++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index f7ba4f6..b2656df 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,6 @@ "homepage": "https://github.com/comp426-2022-spring/a03-sep0225#readme", "dependencies": { "express": "^4.18.1", - "yargs": "^17.4.1" + "minimist": "^1.2.6" } } diff --git a/server.js b/server.js index 3028467..98ae5ab 100644 --- a/server.js +++ b/server.js @@ -2,20 +2,11 @@ const express = require('express') const app = express() -//const min = require('minimist') -//const args = min(process.argv.slice(2)) +const min = require('minimist') +const args = min(process.argv.slice(2)) -//args['port'] -//const port = args.port || process.env.PORT || 5000 - -const args = require('yargs').argv -let port - -if (typeof args.port === "undefined") { - port = 5000; -} else { - port = args.port -} +args['port'] +const port = args.port || process.env.PORT || 5000 // Start an app server const server = app.listen(port, () => { From d7a6cb9306e14d9021ad03a1aae7379ce7c18951 Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 14:01:43 -0400 Subject: [PATCH 11/24] this is so frustrating --- server.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/server.js b/server.js index 98ae5ab..ce5e377 100644 --- a/server.js +++ b/server.js @@ -2,11 +2,9 @@ const express = require('express') const app = express() -const min = require('minimist') -const args = min(process.argv.slice(2)) - +const args = require('minimist')(process.argv.slice(2)) args['port'] -const port = args.port || process.env.PORT || 5000 +const port = args.port || 5555 // Start an app server const server = app.listen(port, () => { @@ -23,28 +21,24 @@ app.get('/app/', (req, res) => { }); app.get('/app/flip/', (req, res) => { - let flip = coinFlip() - res.statusCode = 200; - res.json({ 'flip': flip }) + const flip = coinFlip() + res.status(200).json({ "flip" : flip }) }) app.get('/app/flips/:number', (req, res) => { let flips = coinFlips(req.params.number) let total = countFlips(flips) - res.statusCode = 200 - res.json({ 'raw': flips, 'summary': total }) + res.status(200).json({ 'raw': flips, 'summary': total }) }) app.get('/app/flip/call/heads', (req, res) => { - let heads = flipACoin('heads') - res.statusCode = 200 - res.json(heads) + const flipResult = flipACoin('heads') + res.status(200).json({ 'call' : flipResult.call, 'flip' : flipResult.flip, 'result' : flipResult.result }) }) app.get('/app/flip/call/tails', (req, res) => { - let tails = flipACoin('tails') - res.statusCode = 200 - res.json(tails) + const flipResult = flipACoin('tails') + res.status(200).json({ 'call' : flipResult.call, 'flip' : flipResult.flip, 'result' : flipResult.result }) }) // Default response for any other request From 574e615faeed497c976ff3329565dcabf53bc95f Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 14:04:27 -0400 Subject: [PATCH 12/24] cmonnnnn --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b2656df..2248bcc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "a03-sep0225", "version": "1.0.0", "description": "building an API", - "main": "server.js", + "main": "index.js", "scripts": { "test": "node server.js --port=5555", "start": "node server.js" @@ -19,6 +19,7 @@ "homepage": "https://github.com/comp426-2022-spring/a03-sep0225#readme", "dependencies": { "express": "^4.18.1", - "minimist": "^1.2.6" + "minimist": "^1.2.6", + "yargs": "^17.4.1" } } From c3371bc3e52af7ea356c5efca273f1a80909f464 Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 14:15:38 -0400 Subject: [PATCH 13/24] please --- server.js | 156 +++++++++++++++++------------------------------------- 1 file changed, 48 insertions(+), 108 deletions(-) diff --git a/server.js b/server.js index ce5e377..5b13c0d 100644 --- a/server.js +++ b/server.js @@ -1,4 +1,3 @@ -// Require Express.js const express = require('express') const app = express() @@ -6,20 +5,59 @@ const args = require('minimist')(process.argv.slice(2)) args['port'] const port = args.port || 5555 -// Start an app server const server = app.listen(port, () => { console.log('App listening on port %PORT%'.replace('%PORT%', port)) }); app.get('/app/', (req, res) => { - // Respond with status 200 res.statusCode = 200; - // Respond with status message "OK" res.statusMessage = 'OK'; res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' }); res.end(res.statusCode+ ' ' +res.statusMessage) }); +function coinFlip() { + return Math.random() < 0.6 ? ("heads") : ("tails") +} + +function coinFlips(flips) { + const arr = []; + for (let i = 0; i < flips; i++) { + arr[i] = coinFlip(); + } + return arr; +} + +function countFlips(array) { + let h_amt = 0; + let t_amt = 0; + for (let i = 0; i < array.length; i++) { + if (array[i] == "heads") { + h_amt += 1; + } else { + t_amt += 1; + } + } + if (h_amt == 0) { + return "{ tails: " + t_amt + " }"; + } + if (t_amt == 0) { + return "{ heads: " + h_amt + " }"; + } + return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; +} + +function flipACoin(call) { + let flip = coinFlip(); + let result = ""; + if (call == flip) { + result = "win"; + } else { + result = "lose"; + } + return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; +} + app.get('/app/flip/', (req, res) => { const flip = coinFlip() res.status(200).json({ "flip" : flip }) @@ -31,114 +69,16 @@ app.get('/app/flips/:number', (req, res) => { res.status(200).json({ 'raw': flips, 'summary': total }) }) -app.get('/app/flip/call/heads', (req, res) => { - const flipResult = flipACoin('heads') - res.status(200).json({ 'call' : flipResult.call, 'flip' : flipResult.flip, 'result' : flipResult.result }) -}) - app.get('/app/flip/call/tails', (req, res) => { const flipResult = flipACoin('tails') res.status(200).json({ 'call' : flipResult.call, 'flip' : flipResult.flip, 'result' : flipResult.result }) }) -// Default response for any other request +app.get('/app/flip/call/heads', (req, res) => { + const flipResult = flipACoin('heads') + res.status(200).json({ 'call' : flipResult.call, 'flip' : flipResult.flip, 'result' : flipResult.result }) +}) + app.use(function(req, res){ res.status(404).send('404 NOT FOUND') -}); - -/** Simple coin flip - * - * Write a function that accepts no parameters but returns either heads or tails at random. - * - * @param {*} - * @returns {string} - * - * example: coinFlip() - * returns: heads - * - */ - - function coinFlip() { - return Math.random() < 0.6 ? ("heads") : ("tails") - } - - /** Multiple coin flips - * - * Write a function that accepts one parameter (number of flips) and returns an array of - * resulting "heads" or "tails". - * - * @param {number} flips - * @returns {string[]} results - * - * example: coinFlips(10) - * returns: - * [ - 'heads', 'heads', - 'heads', 'tails', - 'heads', 'tails', - 'tails', 'heads', - 'tails', 'heads' - ] - */ - - function coinFlips(flips) { - const arr = []; - for (let i = 0; i < flips; i++) { - arr[i] = coinFlip(); - } - return arr; - } - - /** Count multiple flips - * - * Write a function that accepts an array consisting of "heads" or "tails" - * (e.g. the results of your `coinFlips()` function) and counts each, returning - * an object containing the number of each. - * - * example: conutFlips(['heads', 'heads','heads', 'tails','heads', 'tails','tails', 'heads','tails', 'heads']) - * { tails: 5, heads: 5 } - * - * @param {string[]} array - * @returns {{ heads: number, tails: number }} - */ - - function countFlips(array) { - let h_amt = 0; - let t_amt = 0; - for (let i = 0; i < array.length; i++) { - if (array[i] == "heads") { - h_amt += 1; - } else { - t_amt += 1; - } - } - if (h_amt == 0) { - return "{ tails: " + t_amt + " }"; - } - if (t_amt == 0) { - return "{ heads: " + h_amt + " }"; - } - return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; - } - - /** Flip a coin! - * - * Write a function that accepts one input parameter: a string either "heads" or "tails", flips a coin, and then records "win" or "lose". - * - * @param {string} call - * @returns {object} with keys that are the input param (heads or tails), a flip (heads or tails), and the result (win or lose). See below example. - * - * example: flipACoin('tails') - * returns: { call: 'tails', flip: 'heads', result: 'lose' } - */ - - function flipACoin(call) { - let flip = coinFlip(); - let result = ""; - if (call == flip) { - result = "win"; - } else { - result = "lose"; - } - return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; - } +}); \ No newline at end of file From 34dd4279644c9f74c6085c7caa477ec5b0a37e5f Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 14:23:57 -0400 Subject: [PATCH 14/24] :( --- package.json | 3 +- server.js | 87 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 2248bcc..ab0583f 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,7 @@ "description": "building an API", "main": "index.js", "scripts": { - "test": "node server.js --port=5555", - "start": "node server.js" + "test": "node server.js --port=5555" }, "repository": { "type": "git", diff --git a/server.js b/server.js index 5b13c0d..65fc3c2 100644 --- a/server.js +++ b/server.js @@ -17,45 +17,80 @@ app.get('/app/', (req, res) => { }); function coinFlip() { - return Math.random() < 0.6 ? ("heads") : ("tails") + // return Math.random() < 0.6 ? ("heads") : ("tails") + var ran = Math.random(); + if (ran < 0.5) { + return "heads"; + } + else { + return "tails"; + } } function coinFlips(flips) { - const arr = []; - for (let i = 0; i < flips; i++) { - arr[i] = coinFlip(); - } - return arr; + // const arr = []; + // for (let i = 0; i < flips; i++) { + // arr[i] = coinFlip(); + // } + // return arr; + if (flips < 0 || flips == '' || flips == null) { + console.log('Error: no input'); + } else { + var list = []; + for(var i = 0; i < flips; i++) { + list.push(coinFlip()); + } + return list; + } } function countFlips(array) { - let h_amt = 0; - let t_amt = 0; - for (let i = 0; i < array.length; i++) { - if (array[i] == "heads") { - h_amt += 1; - } else { - t_amt += 1; - } - } - if (h_amt == 0) { - return "{ tails: " + t_amt + " }"; - } - if (t_amt == 0) { - return "{ heads: " + h_amt + " }"; + // let h_amt = 0; + // let t_amt = 0; + // for (let i = 0; i < array.length; i++) { + // if (array[i] == "heads") { + // h_amt += 1; + // } else { + // t_amt += 1; + // } + // } + // if (h_amt == 0) { + // return "{ tails: " + t_amt + " }"; + // } + // if (t_amt == 0) { + // return "{ heads: " + h_amt + " }"; + // } + // return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; + var heads = 0; + var tails = 0; + for(var i = 0; array.length > i; i++) { + if (array[i] == "heads") { + heads++; + } + else { + tails++ + } } - return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; + return {'heads' : heads, 'tails' : tails} } function flipACoin(call) { - let flip = coinFlip(); - let result = ""; + // let flip = coinFlip(); + // let result = ""; + // if (call == flip) { + // result = "win"; + // } else { + // result = "lose"; + // } + // return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; + var flip = coinFlip(); + var result = "" if (call == flip) { - result = "win"; + result = "win" } else { - result = "lose"; + result = "lose" } - return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; + return {"call": call, "flip": flip, "result": result}; } app.get('/app/flip/', (req, res) => { From 9bbfead85392d57b62de7898950a0e7a11ed2907 Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 14:31:23 -0400 Subject: [PATCH 15/24] blahh --- server.js | 103 ++++++++++++++++++------------------------------------ 1 file changed, 34 insertions(+), 69 deletions(-) diff --git a/server.js b/server.js index 65fc3c2..9d718a4 100644 --- a/server.js +++ b/server.js @@ -3,96 +3,61 @@ const app = express() const args = require('minimist')(process.argv.slice(2)) args['port'] -const port = args.port || 5555 +const port = args.port || process.env.PORT || 5000; const server = app.listen(port, () => { console.log('App listening on port %PORT%'.replace('%PORT%', port)) }); -app.get('/app/', (req, res) => { - res.statusCode = 200; - res.statusMessage = 'OK'; - res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' }); - res.end(res.statusCode+ ' ' +res.statusMessage) -}); - function coinFlip() { - // return Math.random() < 0.6 ? ("heads") : ("tails") - var ran = Math.random(); - if (ran < 0.5) { - return "heads"; - } - else { - return "tails"; - } + return Math.random() < 0.6 ? ("heads") : ("tails") } function coinFlips(flips) { - // const arr = []; - // for (let i = 0; i < flips; i++) { - // arr[i] = coinFlip(); - // } - // return arr; - if (flips < 0 || flips == '' || flips == null) { - console.log('Error: no input'); - } else { - var list = []; - for(var i = 0; i < flips; i++) { - list.push(coinFlip()); - } - return list; - } + const arr = []; + for (let i = 0; i < flips; i++) { + arr[i] = coinFlip(); + } + return arr; } function countFlips(array) { - // let h_amt = 0; - // let t_amt = 0; - // for (let i = 0; i < array.length; i++) { - // if (array[i] == "heads") { - // h_amt += 1; - // } else { - // t_amt += 1; - // } - // } - // if (h_amt == 0) { - // return "{ tails: " + t_amt + " }"; - // } - // if (t_amt == 0) { - // return "{ heads: " + h_amt + " }"; - // } - // return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; - var heads = 0; - var tails = 0; - for(var i = 0; array.length > i; i++) { - if (array[i] == "heads") { - heads++; - } - else { - tails++ - } + let h_amt = 0; + let t_amt = 0; + for (let i = 0; i < array.length; i++) { + if (array[i] == "heads") { + h_amt += 1; + } else { + t_amt += 1; + } + } + if (h_amt == 0) { + return "{ tails: " + t_amt + " }"; + } + if (t_amt == 0) { + return "{ heads: " + h_amt + " }"; } - return {'heads' : heads, 'tails' : tails} + return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; } function flipACoin(call) { - // let flip = coinFlip(); - // let result = ""; - // if (call == flip) { - // result = "win"; - // } else { - // result = "lose"; - // } - // return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; - var flip = coinFlip(); - var result = "" + let flip = coinFlip(); + let result = ""; if (call == flip) { - result = "win" + result = "win"; } else { - result = "lose" + result = "lose"; } - return {"call": call, "flip": flip, "result": result}; + return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; } +app.get('/app/', (req, res) => { + res.statusCode = 200; + res.statusMessage = 'OK'; + res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' }); + res.end(res.statusCode+ ' ' +res.statusMessage) +}); + app.get('/app/flip/', (req, res) => { const flip = coinFlip() res.status(200).json({ "flip" : flip }) From ab730d6f850df8c74ddbecb06a2130b362300178 Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 14:37:48 -0400 Subject: [PATCH 16/24] I can't anymore --- server.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/server.js b/server.js index 9d718a4..546166f 100644 --- a/server.js +++ b/server.js @@ -63,20 +63,15 @@ app.get('/app/flip/', (req, res) => { res.status(200).json({ "flip" : flip }) }) -app.get('/app/flips/:number', (req, res) => { - let flips = coinFlips(req.params.number) - let total = countFlips(flips) +app.get('/app/flips/:number([0-9]{1,3})', (req, res) => { + const flips = coinFlips(req.params.number) + const total = countFlips(flips) res.status(200).json({ 'raw': flips, 'summary': total }) }) -app.get('/app/flip/call/tails', (req, res) => { - const flipResult = flipACoin('tails') - res.status(200).json({ 'call' : flipResult.call, 'flip' : flipResult.flip, 'result' : flipResult.result }) -}) - -app.get('/app/flip/call/heads', (req, res) => { - const flipResult = flipACoin('heads') - res.status(200).json({ 'call' : flipResult.call, 'flip' : flipResult.flip, 'result' : flipResult.result }) +app.get('/app/flip/call/:guess(heads|tails)/', (req, res) => { + const flipResult = flipACoin(req.params.guess) + res.status(200).json(flipResult) }) app.use(function(req, res){ From f4d1f8ec6248dbe1fbfef43888b5d71960d71d73 Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sat, 30 Apr 2022 17:24:10 -0400 Subject: [PATCH 17/24] cmonnnnnnnn --- server.js | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/server.js b/server.js index 546166f..3bef773 100644 --- a/server.js +++ b/server.js @@ -58,22 +58,43 @@ app.get('/app/', (req, res) => { res.end(res.statusCode+ ' ' +res.statusMessage) }); +// app.get('/app/flip/', (req, res) => { +// const flip = coinFlip() +// res.status(200).json({ "flip" : flip }) +// }) + +// app.get('/app/flips/:number([0-9]{1,3})', (req, res) => { +// const flips = coinFlips(req.params.number) +// const total = countFlips(flips) +// res.status(200).json({ 'raw': flips, 'summary': total }) +// }) + +// app.get('/app/flip/call/:guess(heads|tails)/', (req, res) => { +// const flipResult = flipACoin(req.params.guess) +// res.status(200).json(flipResult) +// }) + app.get('/app/flip/', (req, res) => { - const flip = coinFlip() - res.status(200).json({ "flip" : flip }) -}) + const flip = coinFlip() + res.status(200).json({'flip' : flip}) +}); -app.get('/app/flips/:number([0-9]{1,3})', (req, res) => { - const flips = coinFlips(req.params.number) - const total = countFlips(flips) - res.status(200).json({ 'raw': flips, 'summary': total }) -}) +// autograder +app.get('/app/flips/:number/', (req, res) => { + const flips = coinFlips(req.params.number) + const count = countFlips(flips) + + res.status(200).json({'raw' : flips, 'summary' : count}) +}); + +app.get('/app/flip/call/heads', (req, res) => { + res.status(200).json(flipACoin("heads")) +}); -app.get('/app/flip/call/:guess(heads|tails)/', (req, res) => { - const flipResult = flipACoin(req.params.guess) - res.status(200).json(flipResult) -}) +app.get('/app/flip/call/tails', (req, res) => { + res.status(200).json(flipACoin("tails")) +}); app.use(function(req, res){ - res.status(404).send('404 NOT FOUND') + res.status(404).send('404 NOT FOUND') }); \ No newline at end of file From ee234ce408aa497d4516d9460c6036917e483305 Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sun, 1 May 2022 16:41:28 -0400 Subject: [PATCH 18/24] if this doesn't work then i give up --- server.js | 241 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 167 insertions(+), 74 deletions(-) diff --git a/server.js b/server.js index 3bef773..07c678e 100644 --- a/server.js +++ b/server.js @@ -1,100 +1,193 @@ -const express = require('express') -const app = express() +// const express = require('express') +// const app = express() -const args = require('minimist')(process.argv.slice(2)) -args['port'] -const port = args.port || process.env.PORT || 5000; +// const args = require('minimist')(process.argv.slice(2)) +// args['port'] +// const port = args.port || process.env.PORT || 5000; -const server = app.listen(port, () => { - console.log('App listening on port %PORT%'.replace('%PORT%', port)) -}); +// const server = app.listen(port, () => { +// console.log('App listening on port %PORT%'.replace('%PORT%', port)) +// }); -function coinFlip() { - return Math.random() < 0.6 ? ("heads") : ("tails") -} +// function coinFlip() { +// return Math.random() < 0.6 ? ("heads") : ("tails") +// } -function coinFlips(flips) { - const arr = []; - for (let i = 0; i < flips; i++) { - arr[i] = coinFlip(); - } - return arr; -} +// function coinFlips(flips) { +// const arr = []; +// for (let i = 0; i < flips; i++) { +// arr[i] = coinFlip(); +// } +// return arr; +// } -function countFlips(array) { - let h_amt = 0; - let t_amt = 0; - for (let i = 0; i < array.length; i++) { - if (array[i] == "heads") { - h_amt += 1; - } else { - t_amt += 1; - } - } - if (h_amt == 0) { - return "{ tails: " + t_amt + " }"; - } - if (t_amt == 0) { - return "{ heads: " + h_amt + " }"; - } - return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; -} +// function countFlips(array) { +// let h_amt = 0; +// let t_amt = 0; +// for (let i = 0; i < array.length; i++) { +// if (array[i] == "heads") { +// h_amt += 1; +// } else { +// t_amt += 1; +// } +// } +// if (h_amt == 0) { +// return "{ tails: " + t_amt + " }"; +// } +// if (t_amt == 0) { +// return "{ heads: " + h_amt + " }"; +// } +// return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; +// } -function flipACoin(call) { - let flip = coinFlip(); - let result = ""; - if (call == flip) { - result = "win"; - } else { - result = "lose"; - } - return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; -} +// function flipACoin(call) { +// let flip = coinFlip(); +// let result = ""; +// if (call == flip) { +// result = "win"; +// } else { +// result = "lose"; +// } +// return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; +// } -app.get('/app/', (req, res) => { - res.statusCode = 200; - res.statusMessage = 'OK'; - res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' }); - res.end(res.statusCode+ ' ' +res.statusMessage) -}); +// app.get('/app/', (req, res) => { +// res.statusCode = 200; +// res.statusMessage = 'OK'; +// res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' }); +// res.end(res.statusCode+ ' ' +res.statusMessage) +// }); + +// // app.get('/app/flip/', (req, res) => { +// // const flip = coinFlip() +// // res.status(200).json({ "flip" : flip }) +// // }) + +// // app.get('/app/flips/:number([0-9]{1,3})', (req, res) => { +// // const flips = coinFlips(req.params.number) +// // const total = countFlips(flips) +// // res.status(200).json({ 'raw': flips, 'summary': total }) +// // }) + +// // app.get('/app/flip/call/:guess(heads|tails)/', (req, res) => { +// // const flipResult = flipACoin(req.params.guess) +// // res.status(200).json(flipResult) +// // }) // app.get('/app/flip/', (req, res) => { -// const flip = coinFlip() -// res.status(200).json({ "flip" : flip }) -// }) +// const flip = coinFlip() +// res.status(200).json({'flip' : flip}) +// }); + +// // autograder +// app.get('/app/flips/:number/', (req, res) => { +// const flips = coinFlips(req.params.number) +// const count = countFlips(flips) + +// res.status(200).json({'raw' : flips, 'summary' : count}) +// }); + +// app.get('/app/flip/call/heads', (req, res) => { +// res.status(200).json(flipACoin("heads")) +// }); + +// app.get('/app/flip/call/tails', (req, res) => { +// res.status(200).json(flipACoin("tails")) +// }); + +// app.use(function(req, res){ +// res.status(404).send('404 NOT FOUND') +// }); + +const express = require('express') +const app = express() -// app.get('/app/flips/:number([0-9]{1,3})', (req, res) => { -// const flips = coinFlips(req.params.number) -// const total = countFlips(flips) -// res.status(200).json({ 'raw': flips, 'summary': total }) -// }) -// app.get('/app/flip/call/:guess(heads|tails)/', (req, res) => { -// const flipResult = flipACoin(req.params.guess) -// res.status(200).json(flipResult) -// }) +// Start an app server +const args = require('minimist')(process.argv.slice(2)) +args['port'] +const port = args.port || process.env.PORT || 5000 +const server = app.listen(port, () => { + // console.log('App listening on port %PORT%'.replace('%PORT%',port)) +}); + +app.get('/app/', (req, res) => { + // Respond with status 200 + res.statusCode = 200; + // Respond with status message "OK" + res.statusMessage = 'OK'; + res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' }); + res.end(res.statusCode+ ' ' +res.statusMessage) +}); app.get('/app/flip/', (req, res) => { - const flip = coinFlip() - res.status(200).json({'flip' : flip}) + const flip = coinFlip() + res.status(200).json({'flip' : flip}) }); // autograder app.get('/app/flips/:number/', (req, res) => { - const flips = coinFlips(req.params.number) - const count = countFlips(flips) - - res.status(200).json({'raw' : flips, 'summary' : count}) + const flips = coinFlips(req.params.number) + const count = countFlips(flips) + + res.status(200).json({'raw' : flips, 'summary' : count}) }); app.get('/app/flip/call/heads', (req, res) => { - res.status(200).json(flipACoin("heads")) + res.status(200).json(flipACoin("heads")) }); app.get('/app/flip/call/tails', (req, res) => { - res.status(200).json(flipACoin("tails")) + res.status(200).json(flipACoin("tails")) }); +// Default response for any other request app.use(function(req, res){ - res.status(404).send('404 NOT FOUND') -}); \ No newline at end of file + res.status(404).send('404 NOT FOUND') +}); + + +function coinFlip() { + + let num = Math.round(Math.random())%2; + + if(num==0) {return "heads"}; + return "tails"; +} + +function coinFlips(flips) { + let arr= []; + for(let i=0; i Date: Sun, 1 May 2022 17:03:46 -0400 Subject: [PATCH 19/24] cleaning things up --- server.js | 113 ++---------------------------------------------------- 1 file changed, 3 insertions(+), 110 deletions(-) diff --git a/server.js b/server.js index 07c678e..5696e5b 100644 --- a/server.js +++ b/server.js @@ -1,120 +1,16 @@ -// const express = require('express') -// const app = express() - -// const args = require('minimist')(process.argv.slice(2)) -// args['port'] -// const port = args.port || process.env.PORT || 5000; - -// const server = app.listen(port, () => { -// console.log('App listening on port %PORT%'.replace('%PORT%', port)) -// }); - -// function coinFlip() { -// return Math.random() < 0.6 ? ("heads") : ("tails") -// } - -// function coinFlips(flips) { -// const arr = []; -// for (let i = 0; i < flips; i++) { -// arr[i] = coinFlip(); -// } -// return arr; -// } - -// function countFlips(array) { -// let h_amt = 0; -// let t_amt = 0; -// for (let i = 0; i < array.length; i++) { -// if (array[i] == "heads") { -// h_amt += 1; -// } else { -// t_amt += 1; -// } -// } -// if (h_amt == 0) { -// return "{ tails: " + t_amt + " }"; -// } -// if (t_amt == 0) { -// return "{ heads: " + h_amt + " }"; -// } -// return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; -// } - -// function flipACoin(call) { -// let flip = coinFlip(); -// let result = ""; -// if (call == flip) { -// result = "win"; -// } else { -// result = "lose"; -// } -// return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; -// } - -// app.get('/app/', (req, res) => { -// res.statusCode = 200; -// res.statusMessage = 'OK'; -// res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' }); -// res.end(res.statusCode+ ' ' +res.statusMessage) -// }); - -// // app.get('/app/flip/', (req, res) => { -// // const flip = coinFlip() -// // res.status(200).json({ "flip" : flip }) -// // }) - -// // app.get('/app/flips/:number([0-9]{1,3})', (req, res) => { -// // const flips = coinFlips(req.params.number) -// // const total = countFlips(flips) -// // res.status(200).json({ 'raw': flips, 'summary': total }) -// // }) - -// // app.get('/app/flip/call/:guess(heads|tails)/', (req, res) => { -// // const flipResult = flipACoin(req.params.guess) -// // res.status(200).json(flipResult) -// // }) - -// app.get('/app/flip/', (req, res) => { -// const flip = coinFlip() -// res.status(200).json({'flip' : flip}) -// }); - -// // autograder -// app.get('/app/flips/:number/', (req, res) => { -// const flips = coinFlips(req.params.number) -// const count = countFlips(flips) - -// res.status(200).json({'raw' : flips, 'summary' : count}) -// }); - -// app.get('/app/flip/call/heads', (req, res) => { -// res.status(200).json(flipACoin("heads")) -// }); - -// app.get('/app/flip/call/tails', (req, res) => { -// res.status(200).json(flipACoin("tails")) -// }); - -// app.use(function(req, res){ -// res.status(404).send('404 NOT FOUND') -// }); - const express = require('express') const app = express() -// Start an app server const args = require('minimist')(process.argv.slice(2)) args['port'] const port = args.port || process.env.PORT || 5000 const server = app.listen(port, () => { - // console.log('App listening on port %PORT%'.replace('%PORT%',port)) + console.log('App listening on port %PORT%'.replace('%PORT%',port)) }); app.get('/app/', (req, res) => { - // Respond with status 200 res.statusCode = 200; - // Respond with status message "OK" res.statusMessage = 'OK'; res.writeHead( res.statusCode, { 'Content-Type' : 'text/plain' }); res.end(res.statusCode+ ' ' +res.statusMessage) @@ -125,12 +21,10 @@ app.get('/app/flip/', (req, res) => { res.status(200).json({'flip' : flip}) }); -// autograder app.get('/app/flips/:number/', (req, res) => { const flips = coinFlips(req.params.number) - const count = countFlips(flips) - - res.status(200).json({'raw' : flips, 'summary' : count}) + const total = countFlips(flips) + res.status(200).json({'raw' : flips, 'summary' : total}) }); app.get('/app/flip/call/heads', (req, res) => { @@ -141,7 +35,6 @@ app.get('/app/flip/call/tails', (req, res) => { res.status(200).json(flipACoin("tails")) }); -// Default response for any other request app.use(function(req, res){ res.status(404).send('404 NOT FOUND') }); From 592f0caa405c26b6506e533a9edb13663626f37f Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sun, 1 May 2022 17:31:06 -0400 Subject: [PATCH 20/24] final --- server.js | 61 +++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/server.js b/server.js index 5696e5b..0be8db1 100644 --- a/server.js +++ b/server.js @@ -1,7 +1,6 @@ const express = require('express') const app = express() - const args = require('minimist')(process.argv.slice(2)) args['port'] const port = args.port || process.env.PORT || 5000 @@ -39,48 +38,44 @@ app.use(function(req, res){ res.status(404).send('404 NOT FOUND') }); - function coinFlip() { - - let num = Math.round(Math.random())%2; - - if(num==0) {return "heads"}; - return "tails"; + return Math.random() < 0.6 ? ("heads") : ("tails") } function coinFlips(flips) { - let arr= []; - for(let i=0; i Date: Sun, 1 May 2022 17:37:01 -0400 Subject: [PATCH 21/24] finished --- server.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 0be8db1..34d838b 100644 --- a/server.js +++ b/server.js @@ -62,11 +62,11 @@ function countFlips(array) { } if (h_amt == 0) { return "{ tails: " + t_amt + " }"; - } - if (t_amt == 0) { + } else if (t_amt == 0) { return "{ heads: " + h_amt + " }"; + } else { + return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; } - return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; } function flipACoin(call) { @@ -77,5 +77,5 @@ function flipACoin(call) { } else { result = "lose"; } - return "{ call: '" + call + "', flip: '" + flip + "', result: '" + result + "' }"; + return {call: call, flip: flip, result: "win"}; } \ No newline at end of file From 5cd2c159c10429997703bfef50c8467392efaab6 Mon Sep 17 00:00:00 2001 From: "@sep0225" Date: Sun, 1 May 2022 18:34:25 -0400 Subject: [PATCH 22/24] I think this is it --- server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 34d838b..4a15b46 100644 --- a/server.js +++ b/server.js @@ -65,7 +65,7 @@ function countFlips(array) { } else if (t_amt == 0) { return "{ heads: " + h_amt + " }"; } else { - return "{ heads: " + h_amt + ", tails: " + t_amt + " }"; + return {"heads":h_amt, "tails":t_amt}; } } @@ -77,5 +77,5 @@ function flipACoin(call) { } else { result = "lose"; } - return {call: call, flip: flip, result: "win"}; + return {call: call, flip: flip, result: result}; } \ No newline at end of file From 15cc0a92803b347ec3afecdc3487c626f659d121 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Thu, 5 May 2022 17:49:50 +0000 Subject: [PATCH 23/24] Update GitHub Classroom Autograding --- .github/classroom/autograding.json | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/classroom/autograding.json b/.github/classroom/autograding.json index 1a99140..7c0fc2b 100644 --- a/.github/classroom/autograding.json +++ b/.github/classroom/autograding.json @@ -1,14 +1,14 @@ { "tests": [ { - "name": "Default /app/ endpoint", + "name": "Default endpoint", "setup": "npm install", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl -I http://localhost:${PORT}/app/ && sleep 5s", "input": "", "output": "HTTP\\/(1.1|2)\\s*200\\s*(OK)?", "comparison": "regex", "timeout": 10, - "points": 7500 + "points": 8334 }, { "name": "Nonexistent endpoint", @@ -18,87 +18,87 @@ "output": "HTTP\\/(1.1|2)\\s*404\\s*(Not Found)?", "comparison": "regex", "timeout": 10, - "points": 7500 + "points": 8334 }, { - "name": "Random coin flip endpoint &#47;app&#47;flip", + "name": "Random coin flip endpoint", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl http://localhost:${PORT}/app/flip/ && sleep 5s", "input": "", "output": "\\{\"flip\":\"(heads|tails)\"\\}", "comparison": "regex", "timeout": 10, - "points": 7500 + "points": 8334 }, { - "name": "Flip many coins endpoint /app/flips/:number/", + "name": "Flip many coins endpoint", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; NUMBER=\"$(shuf -i 100-500 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl http://localhost:${PORT}/app/flips/${NUMBER}/ && sleep 5s", "input": "", "output": "\\{\"raw\":\\[\"(heads|tails)\",.*\\],\"summary\":\\{\"(heads|tails)\":[0-9]{1,3},\"(heads|tails)\":[0-9]{1,3}\\}\\}", "comparison": "regex", "timeout": 10, - "points": 7500 + "points": 8333 }, { - "name": "Header check /app/flip/", + "name": "Header check flip", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl -I http://localhost:${PORT}/app/flip/ && sleep 5s", "input": "", "output": "HTTP\\/(1.1|2)\\s*200\\s*(OK)?", "comparison": "regex", "timeout": 10, - "points": 7500 + "points": 8333 }, { - "name": "Header check /app/flips/:number/", + "name": "Header check flips", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; NUMBER=\"$(shuf -i 100-500 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl -I http://localhost:${PORT}/app/flips/${NUMBER}/ && sleep 5s", "input": "", "output": "HTTP\\/(1.1|2)\\s*200\\s*(OK)?", "comparison": "regex", "timeout": 10, - "points": 7500 + "points": 8333 }, { - "name": "Call a flip heads at endpoint /app/flip/call/heads/", + "name": "Call a flip heads at endpoint", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl http://localhost:${PORT}/app/flip/call/heads/ && sleep 5s", "input": "", "output": "\\{\"call\":\"heads\",\"flip\":\"(heads|tails)\",\"result\":\"(win|lose)\"\\}", "comparison": "regex", "timeout": 10, - "points": 7500 + "points": 8333 }, { - "name": "Call a flip tails at endpoint /app/flip/call/tails/", + "name": "Call a flip tails at endpoint", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl http://localhost:${PORT}/app/flip/call/tails/ && sleep 5s", "input": "", "output": "\\{\"call\":\"tails\",\"flip\":\"(heads|tails)\",\"result\":\"(win|lose)\"\\}", "comparison": "regex", "timeout": 10, - "points": 7500 + "points": 8333 }, { - "name": "Header check /app/flip/call/heads/", + "name": "Header check", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl -I http://localhost:${PORT}/app/flip/call/heads/ && sleep 5s", "input": "", "output": "HTTP\\/(1.1|2)\\s*200\\s*(OK)?", "comparison": "regex", "timeout": 10, - "points": 7500 + "points": 8333 }, { - "name": "Header check /app/flip/call/tails/", + "name": "Header check", "setup": "", "run": "PORT=\"$(shuf -i 2000-65535 -n 1)\"; (timeout --signal=SIGINT 5 node server.js --port=$PORT; exit 0) & sleep 1s && curl -I http://localhost:${PORT}/app/flip/call/tails/ && sleep 5s", "input": "", "output": "HTTP\\/(1.1|2)\\s*200\\s*(OK)?", "comparison": "regex", "timeout": 10, - "points": 7500 + "points": 8333 }, { "name": "Node version", From 07a239fb1c492adb75af0dcd64eaf4532bd02ae2 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Thu, 5 May 2022 17:49:50 +0000 Subject: [PATCH 24/24] Update GitHub Classroom Autograding Workflow