From 98b8ab0a3c00a53839879dc02b2d7d95689342f7 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 12:50:45 +0100 Subject: [PATCH 01/11] files and backend --- chat-app/backend/server.js | 28 ++++++++++++++++++++++++++++ chat-app/frontend/app.js | 0 chat-app/frontend/index.html | 0 chat-app/frontend/style.css | 0 4 files changed, 28 insertions(+) create mode 100644 chat-app/backend/server.js create mode 100644 chat-app/frontend/app.js create mode 100644 chat-app/frontend/index.html create mode 100644 chat-app/frontend/style.css diff --git a/chat-app/backend/server.js b/chat-app/backend/server.js new file mode 100644 index 0000000..ed2ef57 --- /dev/null +++ b/chat-app/backend/server.js @@ -0,0 +1,28 @@ +import express from "express"; +import cors from "cors"; + +const app = express(); +const port = 5000; + +app.use(cors()); +app.use(express.json()); + +let messages = []; + +// GET messages +app.get("/messages", (req, res) => { + res.json(messages); +}); + +// POST message +app.post("/messages", (req, res) => { + const { username, text } = req.body; + + messages.push({ username, text }); + + res.json({ success: true }); +}); + +app.listen(port, () => { + console.log(`Backend running on http://localhost:${port}`); +}); \ No newline at end of file diff --git a/chat-app/frontend/app.js b/chat-app/frontend/app.js new file mode 100644 index 0000000..e69de29 diff --git a/chat-app/frontend/index.html b/chat-app/frontend/index.html new file mode 100644 index 0000000..e69de29 diff --git a/chat-app/frontend/style.css b/chat-app/frontend/style.css new file mode 100644 index 0000000..e69de29 From 989ab685f597411cd7b4035d0d5510f36fe2fffd Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 13:16:30 +0100 Subject: [PATCH 02/11] .gitignore --- chat-app/backend/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 chat-app/backend/.gitignore diff --git a/chat-app/backend/.gitignore b/chat-app/backend/.gitignore new file mode 100644 index 0000000..1dcef2d --- /dev/null +++ b/chat-app/backend/.gitignore @@ -0,0 +1,2 @@ +node_modules +.env \ No newline at end of file From 6fe5ce181536dffd34ff5521202dd682bf1dd437 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 13:16:50 +0100 Subject: [PATCH 03/11] server.js and htnl --- .vscode/settings.json | 3 + chat-app/backend/package-lock.json | 850 +++++++++++++++++++++++++++++ chat-app/backend/package.json | 16 + chat-app/backend/server.js | 22 +- chat-app/frontend/app.js | 31 ++ chat-app/frontend/index.html | 31 ++ 6 files changed, 939 insertions(+), 14 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 chat-app/backend/package-lock.json create mode 100644 chat-app/backend/package.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f673a71 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5502 +} \ No newline at end of file diff --git a/chat-app/backend/package-lock.json b/chat-app/backend/package-lock.json new file mode 100644 index 0000000..1411cc9 --- /dev/null +++ b/chat-app/backend/package-lock.json @@ -0,0 +1,850 @@ +{ + "name": "backend", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "cors": "^2.8.6", + "express": "^5.2.1" + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/body-parser": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz", + "integrity": "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.3", + "http-errors": "^2.0.0", + "iconv-lite": "^0.7.0", + "on-finished": "^2.4.1", + "qs": "^6.14.1", + "raw-body": "^3.0.1", + "type-is": "^2.0.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.1.0.tgz", + "integrity": "sha512-5jRCH9Z/+DRP7rkvY83B+yGIGX96OYdJmzngqnw2SBSxqCFPd0w2km3s5iawpGX8krnwSGmF0FW5Nhr0Hfai3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", + "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.1", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.3.tgz", + "integrity": "sha512-ej4AhfhfL2Q2zpMmLo7U1Uv9+PyhIZpgQLGT1F9miIGmiCJIoCgSmczFdrc97mWT4kVY72KA+WnnhJ5pghSvSg==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "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==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "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==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", + "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "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==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.15.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.1.tgz", + "integrity": "sha512-6YHEFRL9mfgcAvql/XhwTvf5jKcOiiupt2FiJxHkiX1z4j7WL8J/jRHYLluORvc1XxB5rV20KoeK00gVJamspg==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "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==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "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==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", + "integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==", + "license": "MIT", + "dependencies": { + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + } + } +} diff --git a/chat-app/backend/package.json b/chat-app/backend/package.json new file mode 100644 index 0000000..c3e23ca --- /dev/null +++ b/chat-app/backend/package.json @@ -0,0 +1,16 @@ +{ + "name": "backend", + "version": "1.0.0", + "main": "index.js", + "type": "module", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "cors": "^2.8.6", + "express": "^5.2.1" + } +} diff --git a/chat-app/backend/server.js b/chat-app/backend/server.js index ed2ef57..2cdd5be 100644 --- a/chat-app/backend/server.js +++ b/chat-app/backend/server.js @@ -2,27 +2,21 @@ import express from "express"; import cors from "cors"; const app = express(); -const port = 5000; - -app.use(cors()); +const PORT = 3000; app.use(express.json()); - +app.use(cors()); let messages = []; -// GET messages app.get("/messages", (req, res) => { - res.json(messages); + res.json(messages); }); -// POST message app.post("/messages", (req, res) => { - const { username, text } = req.body; - - messages.push({ username, text }); - - res.json({ success: true }); + const message = req.body; + messages.push(message); + res.status(201).json(message); }); -app.listen(port, () => { - console.log(`Backend running on http://localhost:${port}`); +app.listen(PORT, () => { + console.log(`Server is running on port ${PORT}`); }); \ No newline at end of file diff --git a/chat-app/frontend/app.js b/chat-app/frontend/app.js index e69de29..5cc3608 100644 --- a/chat-app/frontend/app.js +++ b/chat-app/frontend/app.js @@ -0,0 +1,31 @@ +const API = "http://localhost:5000/messages"; + +async function loadMessages() { + const res = await fetch(API); + const data = await res.json(); + + const ul = document.getElementById("messages"); + ul.innerHTML = ""; + + data.forEach(m => { + const li = document.createElement("li"); + li.textContent = `${m.username}: ${m.text}`; + ul.appendChild(li); + }); +} + +async function send() { + const username = document.getElementById("username").value; + const text = document.getElementById("text").value; + + await fetch(API, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ username, text }) + }); + + loadMessages(); +} + +setInterval(loadMessages, 1000); +loadMessages(); \ No newline at end of file diff --git a/chat-app/frontend/index.html b/chat-app/frontend/index.html index e69de29..e361dc9 100644 --- a/chat-app/frontend/index.html +++ b/chat-app/frontend/index.html @@ -0,0 +1,31 @@ + + + + + + + Chat App + + +
+
    +
    + + + +
    +
    + + + + \ No newline at end of file From f1ad1260138f2c3fa53fd826bd63cb33f3d54d89 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 13:19:42 +0100 Subject: [PATCH 04/11] update --- chat-app/frontend/app.js | 71 ++++++++++++++++++++++++------------ chat-app/frontend/index.html | 2 +- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/chat-app/frontend/app.js b/chat-app/frontend/app.js index 5cc3608..66e953a 100644 --- a/chat-app/frontend/app.js +++ b/chat-app/frontend/app.js @@ -1,31 +1,54 @@ -const API = "http://localhost:5000/messages"; +const messagesList = document.getElementById("messages-list"); +const form = document.getElementById("message-form"); +const input = document.getElementById("message-input"); +const usernameInput = document.getElementById("username-input"); -async function loadMessages() { - const res = await fetch(API); - const data = await res.json(); - - const ul = document.getElementById("messages"); - ul.innerHTML = ""; +const BACKEND_URL = + ""; - data.forEach(m => { - const li = document.createElement("li"); - li.textContent = `${m.username}: ${m.text}`; - ul.appendChild(li); - }); +// Fetch and display messages +async function loadMessages() { + const response = await fetch(`${BACKEND_URL}/messages`); + const messages = await response.json(); + messagesList.innerHTML = ""; + messages.forEach((msg) => { + const li = document.createElement("li"); + li.innerHTML = ` +
    + ${msg.username} + ${msg.timeStamp} +
    +
    ${msg.text}
    `; + messagesList.appendChild(li); + }); } -async function send() { - const username = document.getElementById("username").value; - const text = document.getElementById("text").value; +// Handle form submission +form.addEventListener("submit", async (e) => { + e.preventDefault(); - await fetch(API, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ username, text }) - }); + const newMessage = { + username: usernameInput.value, + text: input.value, + timeStamp: new Date().toLocaleTimeString("en-US", { + hour: "numeric", + minute: "2-digit", + hour12: true, + }), + }; - loadMessages(); -} + await fetch(`${BACKEND_URL}/messages`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(newMessage), + }); + + input.value = ""; + usernameInput.value = ""; + loadMessages(); +}); -setInterval(loadMessages, 1000); -loadMessages(); \ No newline at end of file +// Refresh messages every 2 seconds +setInterval(loadMessages, 2000); \ No newline at end of file diff --git a/chat-app/frontend/index.html b/chat-app/frontend/index.html index e361dc9..8686b14 100644 --- a/chat-app/frontend/index.html +++ b/chat-app/frontend/index.html @@ -26,6 +26,6 @@ - + \ No newline at end of file From 4399ba9a4e0cd206af2280777d38fe0ebfd6c2dd Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 13:38:04 +0100 Subject: [PATCH 05/11] backend link --- chat-app/frontend/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chat-app/frontend/app.js b/chat-app/frontend/app.js index 66e953a..4a96b14 100644 --- a/chat-app/frontend/app.js +++ b/chat-app/frontend/app.js @@ -4,7 +4,7 @@ const input = document.getElementById("message-input"); const usernameInput = document.getElementById("username-input"); const BACKEND_URL = - ""; + "https://zabihollah-namazi-chat-app-backend.hosting.codeyourfuture.io"; // Fetch and display messages async function loadMessages() { From 61866c17bd3b9f5b30943b1c74a2b87b1e43b6e8 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 13:53:40 +0100 Subject: [PATCH 06/11] every one second and leave username after every message --- chat-app/frontend/app.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chat-app/frontend/app.js b/chat-app/frontend/app.js index 4a96b14..5824ed8 100644 --- a/chat-app/frontend/app.js +++ b/chat-app/frontend/app.js @@ -46,9 +46,8 @@ form.addEventListener("submit", async (e) => { }); input.value = ""; - usernameInput.value = ""; loadMessages(); }); -// Refresh messages every 2 seconds -setInterval(loadMessages, 2000); \ No newline at end of file +// Refresh messages every 1 seconds +setInterval(loadMessages, 1000); \ No newline at end of file From 3d2a6fd4889aee0f98a351d778a230fcafd5318b Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 13:55:10 +0100 Subject: [PATCH 07/11] loadmessage fun in the end --- chat-app/frontend/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/chat-app/frontend/app.js b/chat-app/frontend/app.js index 5824ed8..5c584b2 100644 --- a/chat-app/frontend/app.js +++ b/chat-app/frontend/app.js @@ -49,5 +49,6 @@ form.addEventListener("submit", async (e) => { loadMessages(); }); +loadMessages(); // Refresh messages every 1 seconds setInterval(loadMessages, 1000); \ No newline at end of file From 6c1f47ab10220981ff8d6c624b720a5b9f6293c4 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 13:58:49 +0100 Subject: [PATCH 08/11] update html --- chat-app/frontend/index.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/chat-app/frontend/index.html b/chat-app/frontend/index.html index 8686b14..60788c1 100644 --- a/chat-app/frontend/index.html +++ b/chat-app/frontend/index.html @@ -8,17 +8,19 @@
    -
      +
      • No messages yet
      + + From 9b7ea351c26a0fbe438168e843e00d0e2375c903 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 15:02:52 +0100 Subject: [PATCH 09/11] updates and css --- chat-app/backend/server.js | 27 ++++++--- chat-app/frontend/app.js | 89 +++++++++++++---------------- chat-app/frontend/index.html | 4 +- chat-app/frontend/style.css | 106 +++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 58 deletions(-) diff --git a/chat-app/backend/server.js b/chat-app/backend/server.js index 2cdd5be..dc2f68d 100644 --- a/chat-app/backend/server.js +++ b/chat-app/backend/server.js @@ -3,20 +3,33 @@ import cors from "cors"; const app = express(); const PORT = 3000; + app.use(express.json()); app.use(cors()); + let messages = []; -app.get("/messages", (req, res) => { +app.get("/", (req, res) => { res.json(messages); }); -app.post("/messages", (req, res) => { - const message = req.body; - messages.push(message); - res.status(201).json(message); +app.post("/", (req, res) => { + const { username, text } = req.body; + + if (!username || !text) { + return res.status(400).json({ error: "username and text required" }); + } + + messages.push({ + username, + text, + timeStamp: new Date().toLocaleTimeString(), + }); + + res.status(201).json({ success: true }); }); app.listen(PORT, () => { - console.log(`Server is running on port ${PORT}`); -}); \ No newline at end of file + console.log("Server running on port 3000"); +}); + diff --git a/chat-app/frontend/app.js b/chat-app/frontend/app.js index 5c584b2..c9bba9a 100644 --- a/chat-app/frontend/app.js +++ b/chat-app/frontend/app.js @@ -1,54 +1,45 @@ -const messagesList = document.getElementById("messages-list"); -const form = document.getElementById("message-form"); -const input = document.getElementById("message-input"); -const usernameInput = document.getElementById("username-input"); - -const BACKEND_URL = - "https://zabihollah-namazi-chat-app-backend.hosting.codeyourfuture.io"; - -// Fetch and display messages -async function loadMessages() { - const response = await fetch(`${BACKEND_URL}/messages`); - const messages = await response.json(); - messagesList.innerHTML = ""; - messages.forEach((msg) => { - const li = document.createElement("li"); - li.innerHTML = ` -
      - ${msg.username} - ${msg.timeStamp} -
      -
      ${msg.text}
      `; - messagesList.appendChild(li); - }); -} - -// Handle form submission -form.addEventListener("submit", async (e) => { - e.preventDefault(); - - const newMessage = { - username: usernameInput.value, - text: input.value, - timeStamp: new Date().toLocaleTimeString("en-US", { - hour: "numeric", - minute: "2-digit", - hour12: true, - }), - }; - - await fetch(`${BACKEND_URL}/messages`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(newMessage), +document.addEventListener("DOMContentLoaded", () => { + const messagesList = document.getElementById("messages-list"); + const form = document.getElementById("message-form"); + const input = document.getElementById("message-input"); + const usernameInput = document.getElementById("username-input"); + + const BACKEND_URL = "https://zabihollah-namazi-chat-app-backend.hosting.codeyourfuture.io"; + + async function loadMessages() { + const res = await fetch(BACKEND_URL); + const messages = await res.json(); + + messagesList.innerHTML = ""; + + messages.forEach((msg) => { + const li = document.createElement("li"); + li.innerHTML = ` +
      ${msg.username}
      +
      ${msg.text}
      + ${msg.timeStamp} + `; + messagesList.appendChild(li); + }); + } + + form.addEventListener("submit", async (e) => { + e.preventDefault(); + + await fetch(BACKEND_URL, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + username: usernameInput.value, + text: input.value, + }), + }); + + input.value = ""; + loadMessages(); }); - input.value = ""; loadMessages(); + setInterval(loadMessages, 1000); }); -loadMessages(); -// Refresh messages every 1 seconds -setInterval(loadMessages, 1000); \ No newline at end of file diff --git a/chat-app/frontend/index.html b/chat-app/frontend/index.html index 60788c1..8229a95 100644 --- a/chat-app/frontend/index.html +++ b/chat-app/frontend/index.html @@ -3,7 +3,7 @@ - + Chat App @@ -28,6 +28,6 @@
      - + \ No newline at end of file diff --git a/chat-app/frontend/style.css b/chat-app/frontend/style.css index e69de29..194f640 100644 --- a/chat-app/frontend/style.css +++ b/chat-app/frontend/style.css @@ -0,0 +1,106 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f6f8; + margin: 0; + padding: 0; +} + +.chat-container { + max-width: 600px; + margin: 40px auto; + background: white; + border-radius: 12px; + padding: 20px; + box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1); +} + +/* Messages box */ +#messages-list { + list-style: none; + padding: 10px; + height: 350px; + overflow-y: auto; + border-radius: 10px; + background: #fafafa; + border: 1px solid #eee; + display: flex; + flex-direction: column; + gap: 10px; +} + +/* Each message bubble */ +#messages-list { + list-style: none; + padding: 10px; + height: 350px; + overflow-y: auto; + background: #fafafa; + border: 1px solid #eee; +} + +/* Header (username + time) */ +.message-header { + display: flex; + justify-content: space-between; /* THIS pushes time to right */ + align-items: center; + font-size: 0.85em; + margin-bottom: 5px; + color: #555; +} + +/* Username styling */ +.username { + font-weight: bold; + color: #2c3e50; +} + +/* Time styling (right side) */ +.timestamp { + font-size: 0.75em; + color: #999; + margin-left: auto; +} + +/* Message text */ +.message-text { + font-size: 1em; + color: #222; + line-height: 1.4; + word-wrap: break-word; +} + +/* Form styling */ +form { + display: flex; + flex-direction: column; + gap: 10px; + margin-top: 15px; +} + +input { + padding: 10px; + border: 1px solid #ccc; + border-radius: 8px; + font-size: 1em; +} + +button { + padding: 10px; + background-color: #007bff; + color: white; + border: none; + border-radius: 8px; + cursor: pointer; + font-size: 1em; +} + +button:hover { + background-color: #0056b3; +} + +/* Empty state */ +.empty { + text-align: center; + color: #888; + padding: 20px; +} \ No newline at end of file From 504fc8d8f9fc0fe61aac4f7f04611770d8ffd850 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 15:10:50 +0100 Subject: [PATCH 10/11] update cors and port --- chat-app/backend/server.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/chat-app/backend/server.js b/chat-app/backend/server.js index dc2f68d..b79c966 100644 --- a/chat-app/backend/server.js +++ b/chat-app/backend/server.js @@ -2,10 +2,12 @@ import express from "express"; import cors from "cors"; const app = express(); -const PORT = 3000; +const PORT = process.env.PORT || 3000; app.use(express.json()); -app.use(cors()); +app.use(cors({ + origin: "*" +})); let messages = []; @@ -29,7 +31,7 @@ app.post("/", (req, res) => { res.status(201).json({ success: true }); }); -app.listen(PORT, () => { - console.log("Server running on port 3000"); +app.listen(PORT, "0.0.0.0", () => { + console.log(`Server running on ${PORT}`); }); From 519ffc825ee2de45c667d8a458cf8f5aa15b6148 Mon Sep 17 00:00:00 2001 From: ZabihollahNamazi Date: Mon, 4 May 2026 15:43:21 +0100 Subject: [PATCH 11/11] remove .vscode folder --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index f673a71..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "liveServer.settings.port": 5502 -} \ No newline at end of file