From dd6a9d3da351fca8f2eea8463ff19574f6b6ca73 Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 18:49:22 +0000 Subject: [PATCH 01/36] merge serverapi.js, serverweb.js as server.js --- be/package.json | 1 - be/src/helpers/database.js | 2 +- be/src/helpers/environment.js | 11 --------- be/src/helpers/imports.js | 2 -- be/src/helpers/routers.js | 12 +++++----- be/src/helpers/server.js | 42 +++++++++++++++++++++++++++++++++++ be/src/helpers/serverapi.js | 23 ------------------- be/src/helpers/serverweb.js | 33 --------------------------- be/src/index.js | 6 ++--- be/yarn.lock | 8 ------- fe/src/helpers/api.js | 2 +- 11 files changed, 52 insertions(+), 90 deletions(-) delete mode 100644 be/src/helpers/environment.js create mode 100644 be/src/helpers/server.js delete mode 100644 be/src/helpers/serverapi.js delete mode 100644 be/src/helpers/serverweb.js diff --git a/be/package.json b/be/package.json index c6c5c41..d80d8fe 100644 --- a/be/package.json +++ b/be/package.json @@ -6,7 +6,6 @@ "dependencies": { "bcryptjs": "^2.4.3", "cors": "^2.8.5", - "dotenv": "^16.4.5", "express": "^4.19.2", "express-session": "^1.18.0", "jsonwebtoken": "^9.0.2", diff --git a/be/src/helpers/database.js b/be/src/helpers/database.js index f369093..13fff61 100644 --- a/be/src/helpers/database.js +++ b/be/src/helpers/database.js @@ -3,7 +3,7 @@ import {mng} from "./imports.js"; const connect = async () => { try { await mng.connect('mongodb://localhost:27017/', { dbName: "rentify" }); - console.log('[serverApi] MongoDB connected'); + console.log('[server] MongoDB connected'); } catch (err) { console.error(err.message); process.exit(1); diff --git a/be/src/helpers/environment.js b/be/src/helpers/environment.js deleted file mode 100644 index 752993f..0000000 --- a/be/src/helpers/environment.js +++ /dev/null @@ -1,11 +0,0 @@ -import { env } from "./imports.js"; - -env.config(); - -const serverApiPort = process.env.SERVER_API_PORT; -const serverWebPort = process.env.SERVER_WEB_PORT; - -export { - serverApiPort, - serverWebPort -} diff --git a/be/src/helpers/imports.js b/be/src/helpers/imports.js index 96af44d..2ce7058 100644 --- a/be/src/helpers/imports.js +++ b/be/src/helpers/imports.js @@ -1,7 +1,6 @@ import bcr from "bcryptjs"; import crs from "cors"; import cry from "crypto"; -import env from "dotenv"; import exp from "express"; import jwt from "jsonwebtoken"; import mng from "mongoose"; @@ -13,7 +12,6 @@ export { bcr, crs, cry, - env, exp, jwt, mng, diff --git a/be/src/helpers/routers.js b/be/src/helpers/routers.js index 67af46f..298073e 100644 --- a/be/src/helpers/routers.js +++ b/be/src/helpers/routers.js @@ -3,25 +3,25 @@ import { exp } from "./imports.js"; import { authUser } from "./middlewares.js"; import { propertyAdd, propertyDelete, propertyDetail, propertyList, propertyUpdate, userLogin, userRegister } from "./controllers.js"; +const apiRouter = exp.Router(); const userRouter = exp.Router(); +const propertyRouter = exp.Router(); + +apiRouter.use('/property', propertyRouter); +apiRouter.use('/user', userRouter); userRouter.put('/register', userRegister); userRouter.post('/login', userLogin); -const propertyRouter = exp.Router(); - propertyRouter.get('/', propertyList); - propertyRouter.get('/detail/:id', propertyDetail); propertyRouter.use('', authUser); propertyRouter.put('/', propertyAdd); - propertyRouter.post('/detail/:id', propertyUpdate); propertyRouter.delete('/detail/:id', propertyDelete); export { - userRouter, - propertyRouter + apiRouter }; diff --git a/be/src/helpers/server.js b/be/src/helpers/server.js new file mode 100644 index 0000000..62eb888 --- /dev/null +++ b/be/src/helpers/server.js @@ -0,0 +1,42 @@ +import { crs, exp, pth, url } from "./imports.js"; + +import { connect as connectDB } from "./database.js"; +import { apiRouter } from "./routers.js"; + +const startServer = () => { + const app = exp(); + + const serverPort = process.env.SERVER_PORT; + + const staticDir = pth.join(pth.dirname(url.fileURLToPath(import.meta.url)), "../../../fe/build"); + + app.use(crs()); + app.use(exp.json()); + + app.use('/api', apiRouter); + + app.use((req, res, next) => { + if (/(.ico|.js|.css|.jpg|.png|.map)$/i.test(req.path)) { + next(); + } else { + res.header("Cache-Control", "private, no-cache, no-store, must-revalidate"); + res.header("Expires", "-1"); + res.header("Pragma", "no-cache"); + res.sendFile(`${staticDir}/index.html`); + } + }); + + app.use(exp.static(staticDir)); + + app.get('/', (req, res) => { + res.sendFile(`${staticDir}/index.html`) + }); + + connectDB().then(() => {}); + + app.listen(serverPort, () => { + console.log(`[server] Listening on port ${serverPort}`); + }); +}; + +export { startServer }; diff --git a/be/src/helpers/serverapi.js b/be/src/helpers/serverapi.js deleted file mode 100644 index 95b685f..0000000 --- a/be/src/helpers/serverapi.js +++ /dev/null @@ -1,23 +0,0 @@ -import { crs, exp } from "./imports.js"; - -import { connect as connectDB } from "./database.js"; -import { serverApiPort } from "./environment.js"; -import { propertyRouter, userRouter } from "./routers.js"; - -const startServerApi = () => { - const app = exp(); - - app.use(crs()); - app.use(exp.json()); - - app.use('/property', propertyRouter); - app.use('/user', userRouter); - - connectDB().then(() => {}); - - app.listen(serverApiPort, () => { - console.log(`[serverApi] Listening on port ${serverApiPort}`); - }); -}; - -export { startServerApi }; diff --git a/be/src/helpers/serverweb.js b/be/src/helpers/serverweb.js deleted file mode 100644 index 0f39818..0000000 --- a/be/src/helpers/serverweb.js +++ /dev/null @@ -1,33 +0,0 @@ -import { crs, exp, pth, url } from "./imports.js"; - -import { serverWebPort } from "./environment.js"; - -const startServerWeb = () => { - const app = exp(); - - app.use(crs()); - app.use((req, res, next) => { - if (/(.ico|.js|.css|.jpg|.png|.map)$/i.test(req.path)) { - next(); - } else { - res.header("Cache-Control", "private, no-cache, no-store, must-revalidate"); - res.header("Expires", "-1"); - res.header("Pragma", "no-cache"); - res.sendFile(`${statdir}/index.html`); - } - }); - - const statdir = pth.join(pth.dirname(url.fileURLToPath(import.meta.url)), "../../../fe/build"); - - app.use(exp.static(statdir)); - - app.get('/', (req, res) => { - res.sendFile(`${statdir}/index.html`) - }); - - app.listen(serverWebPort, () => { - console.log(`[serverWeb] Listening on port ${serverWebPort}`); - }); -}; - -export { startServerWeb }; diff --git a/be/src/index.js b/be/src/index.js index af4e7aa..e2340ba 100644 --- a/be/src/index.js +++ b/be/src/index.js @@ -1,5 +1,3 @@ -import { startServerApi } from "./helpers/serverapi.js"; -import { startServerWeb } from "./helpers/serverweb.js"; +import { startServer } from "./helpers/server.js"; -startServerApi(); -startServerWeb(); +startServer(); diff --git a/be/yarn.lock b/be/yarn.lock index 844b0f1..cb1e060 100644 --- a/be/yarn.lock +++ b/be/yarn.lock @@ -176,7 +176,6 @@ __metadata: dependencies: bcryptjs: "npm:^2.4.3" cors: "npm:^2.8.5" - dotenv: "npm:^16.4.5" express: "npm:^4.19.2" express-session: "npm:^1.18.0" jsonwebtoken: "npm:^9.0.2" @@ -454,13 +453,6 @@ __metadata: languageName: node linkType: hard -"dotenv@npm:^16.4.5": - version: 16.4.5 - resolution: "dotenv@npm:16.4.5" - checksum: 10c0/48d92870076832af0418b13acd6e5a5a3e83bb00df690d9812e94b24aff62b88ade955ac99a05501305b8dc8f1b0ee7638b18493deb6fe93d680e5220936292f - languageName: node - linkType: hard - "eastasianwidth@npm:^0.2.0": version: 0.2.0 resolution: "eastasianwidth@npm:0.2.0" diff --git a/fe/src/helpers/api.js b/fe/src/helpers/api.js index 6a18424..0f0dc08 100644 --- a/fe/src/helpers/api.js +++ b/fe/src/helpers/api.js @@ -1,6 +1,6 @@ import aio from "axios"; -const apiUrl = "http://localhost:8080"; +const apiUrl = location.origin + '/api'; const apiRequest = async (method, path, options) => { let url = apiUrl + path; From fa034c83de3e8df571946df121e8d7e646fa39db Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 18:51:46 +0000 Subject: [PATCH 02/36] database.js - connectDB -> connectDatabase --- be/src/helpers/database.js | 4 ++-- be/src/helpers/server.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/be/src/helpers/database.js b/be/src/helpers/database.js index 13fff61..cd9064a 100644 --- a/be/src/helpers/database.js +++ b/be/src/helpers/database.js @@ -1,6 +1,6 @@ import {mng} from "./imports.js"; -const connect = async () => { +const connectDatabase = async () => { try { await mng.connect('mongodb://localhost:27017/', { dbName: "rentify" }); console.log('[server] MongoDB connected'); @@ -10,4 +10,4 @@ const connect = async () => { } }; -export { connect }; +export { connectDatabase }; diff --git a/be/src/helpers/server.js b/be/src/helpers/server.js index 62eb888..495cb75 100644 --- a/be/src/helpers/server.js +++ b/be/src/helpers/server.js @@ -1,6 +1,6 @@ import { crs, exp, pth, url } from "./imports.js"; -import { connect as connectDB } from "./database.js"; +import { connectDatabase } from "./database.js"; import { apiRouter } from "./routers.js"; const startServer = () => { @@ -32,7 +32,7 @@ const startServer = () => { res.sendFile(`${staticDir}/index.html`) }); - connectDB().then(() => {}); + connectDatabase().then(() => {}); app.listen(serverPort, () => { console.log(`[server] Listening on port ${serverPort}`); From 441c933064626e94256a4f5c688f0433019e9d6f Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 18:52:25 +0000 Subject: [PATCH 03/36] Dockerfile - add env SERVER_PORT=80 and update EXPOSE --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c262aeb..246e0ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ COPY --from=sssomeshhh/rentify:fe /root/fe/build /root/fe/build COPY --from=sssomeshhh/rentify:be /root/be /root/be WORKDIR /root/be RUN yarn install -EXPOSE 8000 +ENV SERVER_PORT=80 +EXPOSE 80 RUN echo "mongod > /dev/null 2>&1 & disown ; yarn produce ;" > startApp CMD bash ./startApp From d995fb8abddedc5899029077d4622bfe2d485e57 Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 18:59:28 +0000 Subject: [PATCH 04/36] remove typo in PropertyList.js --- fe/src/components/PropertyList.js | 1 - 1 file changed, 1 deletion(-) diff --git a/fe/src/components/PropertyList.js b/fe/src/components/PropertyList.js index a9e090f..5cafc33 100644 --- a/fe/src/components/PropertyList.js +++ b/fe/src/components/PropertyList.js @@ -72,7 +72,6 @@ const PropertyList = () => { ))} - ; ); }; From b1b4019e660c09145a066eb05b6b025630f08c05 Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 19:04:39 +0000 Subject: [PATCH 05/36] 'window.location' -> 'location.' --- fe/src/components/Header.js | 4 ++-- fe/src/components/Login.js | 2 +- fe/src/components/PropertyDetail.js | 6 +++--- fe/src/components/Register.js | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fe/src/components/Header.js b/fe/src/components/Header.js index 0caef6e..abee620 100644 --- a/fe/src/components/Header.js +++ b/fe/src/components/Header.js @@ -11,8 +11,8 @@ const Header = () => { sessionStorage.removeItem('email'); sessionStorage.removeItem('token'); sessionStorage.removeItem('role'); - window.location.href = window.location.origin; - window.location.reload(); + location.href = location.origin; + location.reload(); alert("Logging out " + email + "...") }; diff --git a/fe/src/components/Login.js b/fe/src/components/Login.js index a7e0b30..7c94855 100644 --- a/fe/src/components/Login.js +++ b/fe/src/components/Login.js @@ -25,7 +25,7 @@ const Login = ({ onClose }) => { }); }; if (!open) { - window.location.href = "/"; + location.href = "/"; } return (
diff --git a/fe/src/components/PropertyDetail.js b/fe/src/components/PropertyDetail.js index 07a46c7..699e9ad 100644 --- a/fe/src/components/PropertyDetail.js +++ b/fe/src/components/PropertyDetail.js @@ -45,7 +45,7 @@ const PropertyDetail = () => { const handleSubmit = (e) => { e.preventDefault(); - apiRequest('POST', window.location, { data: detail, headers: { ...getAuthHeader() } }) + apiRequest('POST', location, { data: detail, headers: { ...getAuthHeader() } }) .then((res) => { console.log('Property updated!', res.data); }) @@ -96,12 +96,12 @@ const PropertyDetail = () => { .then((res) => { console.log("Property deleted!", res.data); alert("Property deleted!"); - window.location.href = window.location.origin + '/property/list'; + location.href = location.origin + '/property/list'; }) .catch((err) => { console.error("There was an error deleting the property!", err); alert("There was an error deleting the property!"); - window.location.href = window.location.origin + '/property/list'; + location.href = location.origin + '/property/list'; }); }; diff --git a/fe/src/components/Register.js b/fe/src/components/Register.js index 97bcb93..782669d 100644 --- a/fe/src/components/Register.js +++ b/fe/src/components/Register.js @@ -19,12 +19,12 @@ const Register = () => { .then((res) => { console.log('Registered successfully!', res.data); alert('Registered Successfully! Please Login!'); - window.location.href = window.location.origin; + location.href = location.origin; }) .catch((err) => { console.error('There was an error registering!', err); alert('Cannot Register! Please Try Again!'); - window.location.href = window.location.origin; + location.href = location.origin; }); }; @@ -34,7 +34,7 @@ const Register = () => { SignUp
{ - window.location.href = window.location.origin; + location.href = location.origin; }} style={{justifyContent: "space-between", alignItems: "flex-end"}}> X From 5a1a2da596d96d345e3aaba8634ea3aca7c99666 Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 19:07:57 +0000 Subject: [PATCH 06/36] 'location' -> 'location.pathname' in handleSubmit in PropertyDetail.js --- fe/src/components/PropertyDetail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/src/components/PropertyDetail.js b/fe/src/components/PropertyDetail.js index 699e9ad..0a0bcc0 100644 --- a/fe/src/components/PropertyDetail.js +++ b/fe/src/components/PropertyDetail.js @@ -45,7 +45,7 @@ const PropertyDetail = () => { const handleSubmit = (e) => { e.preventDefault(); - apiRequest('POST', location, { data: detail, headers: { ...getAuthHeader() } }) + apiRequest('POST', location.pathname, { data: detail, headers: { ...getAuthHeader() } }) .then((res) => { console.log('Property updated!', res.data); }) From cb5fef223c8d4122751ab1626f7483a0609ab2da Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 19:46:58 +0000 Subject: [PATCH 07/36] fix views in PropertyDetail --- fe/src/components/PropertyAdd.js | 4 + fe/src/components/PropertyDetail.js | 171 +++++++++++++++++----------- 2 files changed, 106 insertions(+), 69 deletions(-) diff --git a/fe/src/components/PropertyAdd.js b/fe/src/components/PropertyAdd.js index 47aa5f3..123ff2b 100644 --- a/fe/src/components/PropertyAdd.js +++ b/fe/src/components/PropertyAdd.js @@ -26,9 +26,13 @@ const PropertyAdd = () => { apiRequest('PUT', '/property', { data: form, headers: { ...getAuthHeader() } }) .then((res) => { console.log('Property added!', res.data); + alert('Property added!'); + location.href = location.origin + '/property/list'; }) .catch((err) => { console.error('There was an error adding the property!', err); + alert('There was an error adding the property!'); + location.href = location.origin + '/property/list'; }); }; diff --git a/fe/src/components/PropertyDetail.js b/fe/src/components/PropertyDetail.js index 0a0bcc0..c001a0b 100644 --- a/fe/src/components/PropertyDetail.js +++ b/fe/src/components/PropertyDetail.js @@ -10,6 +10,8 @@ import Header from "./Header"; const PropertyDetail = () => { const [detail, setDetail] = useState([]); + const [whichView, setWhichView] = useState('show'); + const getDetail = () => { apiRequest('GET', location.pathname, { headers: { ...getAuthHeader() } }) .then((res) => { @@ -24,16 +26,14 @@ const PropertyDetail = () => { const handleLike = () => { }; - const handleInterested = () => { - return ( -
-

Name: {detail.user.firstName} {detail.user.lastName}

-
-

Email Address: {detail.user.email}

-
-

Phone Number: {detail.user.phoneNumber}

-
- ); + const handleInterested = (e) => { + e.preventDefault(); + if (sessionStorage.getItem('role') == null) { + alert('Please Login!'); + location.href = location.origin + '/login'; + } + setWhichView("user"); + //location.reload(); }; const handleChange = (e) => { @@ -43,14 +43,20 @@ const PropertyDetail = () => { }); }; - const handleSubmit = (e) => { + const handleUpdate = (e) => { e.preventDefault(); apiRequest('POST', location.pathname, { data: detail, headers: { ...getAuthHeader() } }) .then((res) => { - console.log('Property updated!', res.data); + console.log("Property updated!", res.data); + alert("Property updated!"); + setWhichView("show"); + location.reload(); }) .catch((err) => { - console.error('There was an error updating the property!', err); + console.error("There was an error updating the property!", err); + alert("There was an error updating the property!"); + setWhichView("show"); + location.reload(); }); }; @@ -58,41 +64,14 @@ const PropertyDetail = () => { getDetail(); }, []); - const editProperty = () => { - return ( -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- -
- ); + const handleEdit = () => { + setWhichView("edit"); + //location.reload(); }; - const deleteProperty = (e) => { + const handleDelete = (e) => { e.preventDefault(); - apiRequest('DELETE', location.pathname, { headers: { ...getAuthHeader() } }) + apiRequest("DELETE", location.pathname, { headers: { ...getAuthHeader() } }) .then((res) => { console.log("Property deleted!", res.data); alert("Property deleted!"); @@ -105,35 +84,89 @@ const PropertyDetail = () => { }); }; - return ( -
-
-

Title: {detail.title}

-
-

Description: {detail.description}

-
-

Location: {detail.location}

-
-

Bedrooms: {detail.bedrooms}

-
-

Bathrooms: {detail.bathrooms}

-
-

Rent: {detail.rent}

-
- { (sessionStorage.getItem('role') === 'buyer') - ? ( + const renderView = () => { + if (whichView === 'show') { + return ( +
+

Title: {detail.title}

+
+

Description: {detail.description}

+
+

Location: {detail.location}

+
+

Bedrooms: {detail.bedrooms}

+
+

Bathrooms: {detail.bathrooms}

+
+

Rent: {detail.rent}

+
+ {(sessionStorage.getItem("role") === "seller") + ? ( +
+ + +
+ ) + : ( +
+ + +
+ ) + } +
+ ); + } else { + if (whichView === "edit") { + return (
- - +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
- ) - : ( + ); + } else { + return (
- - +

Name: {detail.seller.firstName} {detail.seller.lastName}

+
+

Email Address: {detail.seller.email}

+
+

Phone Number: {detail.seller.phoneNumber}

- ) + ); } + } + } + + return ( +
+
+ {renderView()}
); }; From 5206421ddc302fd82a1c06405f8f491915125ce5 Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 19:58:03 +0000 Subject: [PATCH 08/36] remove be target and refactor --- .github/workflows/build-release.yml | 38 +---------------------------- Dockerfile | 16 +++--------- 2 files changed, 5 insertions(+), 49 deletions(-) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 1739c3f..a1dca6e 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -21,7 +21,7 @@ jobs: uses: docker/build-push-action@v5.3.0 with: builder: ${{ steps.setup_buildx.name }} - context: ./fe + context: . file: Dockerfile target: fe cache-from: | @@ -33,46 +33,10 @@ jobs: tags: | sssomeshhh/rentify:fe sssomeshhh/rentify:fe-${{ github.sha }} - build-args: - XE=fe - - be: - runs-on: ubuntu-22.04 - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Login to Docker Hub - uses: docker/login-action@v3.1.0 - with: - registry: docker.io - username: sssomeshhh - password: ${{ secrets.DOCKER_HUB_TOKEN }} - - name: Setup Docker Buildx - id: setup_buildx - uses: docker/setup-buildx-action@v3.3.0 - - name: Build Target - uses: docker/build-push-action@v5.3.0 - with: - builder: ${{ steps.setup_buildx.name }} - context: ./be - file: Dockerfile - target: be - cache-from: | - type=registry,ref=sssomeshhh/cache:rentify-be - cache-to: | - type=registry,ref=sssomeshhh/cache:rentify-be - load: false - push: true - tags: | - sssomeshhh/rentify:be - sssomeshhh/rentify:be-${{ github.sha }} - build-args: - XE=be fs: runs-on: ubuntu-22.04 needs: - - be - fe steps: - name: Checkout diff --git a/Dockerfile b/Dockerfile index 246e0ec..f303cc7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,8 @@ -FROM node:current-bullseye-slim as base +FROM node:current-bullseye-slim as fe RUN corepack enable -ARG XE -WORKDIR /root/$XE -COPY package.json . -COPY yarn.lock . +COPY ./fe /root +WORKDIR /root/fe RUN yarn install -COPY . . - -FROM base as be -# RUN yarn produce - -FROM base as fe RUN yarn produce FROM mongo:latest as fs @@ -21,7 +13,7 @@ RUN apt-get update && \ apt-get install --yes nodejs && \ corepack enable COPY --from=sssomeshhh/rentify:fe /root/fe/build /root/fe/build -COPY --from=sssomeshhh/rentify:be /root/be /root/be +COPY ./be /root WORKDIR /root/be RUN yarn install ENV SERVER_PORT=80 From 15a030c74c9a73d9ceb3a7cee61fff55e8c9a333 Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 20:06:18 +0000 Subject: [PATCH 09/36] Dockerfile - rearrange steps --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f303cc7..4364485 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM node:current-bullseye-slim as fe RUN corepack enable -COPY ./fe /root WORKDIR /root/fe +COPY ./fe . RUN yarn install RUN yarn produce @@ -13,8 +13,8 @@ RUN apt-get update && \ apt-get install --yes nodejs && \ corepack enable COPY --from=sssomeshhh/rentify:fe /root/fe/build /root/fe/build -COPY ./be /root WORKDIR /root/be +COPY ./be . RUN yarn install ENV SERVER_PORT=80 EXPOSE 80 From 88707c0100f35432af10583569d8bdf95b70d339 Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 20:23:03 +0000 Subject: [PATCH 10/36] Login - add alert for error in handleLogin --- fe/src/components/Login.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fe/src/components/Login.js b/fe/src/components/Login.js index 7c94855..b7b5332 100644 --- a/fe/src/components/Login.js +++ b/fe/src/components/Login.js @@ -22,6 +22,8 @@ const Login = ({ onClose }) => { }) .catch((err) => { console.error('There was an error logging in!', err); + alert('There was an error logging in!'); + setOpen(false); }); }; if (!open) { From 0c32fdce4aa3e343617790cf644ae14c4b6112de Mon Sep 17 00:00:00 2001 From: SomesH S Date: Mon, 27 May 2024 20:24:02 +0000 Subject: [PATCH 11/36] Register - redirect to Login when successful --- fe/src/components/Register.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fe/src/components/Register.js b/fe/src/components/Register.js index 782669d..8a20efc 100644 --- a/fe/src/components/Register.js +++ b/fe/src/components/Register.js @@ -19,12 +19,12 @@ const Register = () => { .then((res) => { console.log('Registered successfully!', res.data); alert('Registered Successfully! Please Login!'); - location.href = location.origin; + location.href = location.origin + '/login'; }) .catch((err) => { console.error('There was an error registering!', err); alert('Cannot Register! Please Try Again!'); - location.href = location.origin; + location.href = location.origin + '/register'; }); }; From 5032c2a3dc1d5c6abb707ab0e18f4d8cba4ebc2c Mon Sep 17 00:00:00 2001 From: SomesH S Date: Tue, 28 May 2024 06:42:37 +0000 Subject: [PATCH 12/36] add evalPopulate() --- be/src/helpers/populate.js | 71 ++++++++++++++++++++++++++++++++++++++ be/src/helpers/server.js | 11 +++++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 be/src/helpers/populate.js diff --git a/be/src/helpers/populate.js b/be/src/helpers/populate.js new file mode 100644 index 0000000..f891e78 --- /dev/null +++ b/be/src/helpers/populate.js @@ -0,0 +1,71 @@ +import {bcr} from "./imports.js"; +import { Property, User } from "./schemas.js"; + +const evalPopulate = async () => { + let sellerId; + await User.create({ + firstName: 'Seller', + lastName: 'User', + email: 'seller.user@email.com', + phoneNumber: '97531', + password: await bcr.hash('Seller.User.97531', 10), + role: 'seller' + }).then((seller) => { + sellerId = seller._id.toString(); + }); + await User.create({ + firstName: 'Buyer', + lastName: 'User', + email: 'buyer.user@email.com', + phoneNumber: '86420', + password: await bcr.hash('Buyer.User.86420', 10), + role: 'buyer' + }); + await Property.create({ + title: 'P1.Title', + description: 'P1.Description', + location: 'L.A', + bedrooms: 1, + bathrooms: 1, + rent: 1000, + seller: sellerId + }); + await Property.create({ + title: 'P2.Title', + description: 'P2.Description', + location: 'L.B', + bedrooms: 2, + bathrooms: 2, + rent: 2000, + seller: sellerId + }); + await Property.create({ + title: 'P3.Title', + description: 'P3.Description', + location: 'L.C', + bedrooms: 3, + bathrooms: 3, + rent: 3000, + seller: sellerId + }); + await Property.create({ + title: 'P4.Title', + description: 'P4.Description', + location: 'L.D', + bedrooms: 4, + bathrooms: 4, + rent: 4000, + seller: sellerId + }); + await Property.create({ + title: 'P5.Title', + description: 'P5.Description', + location: 'L.E', + bedrooms: 5, + bathrooms: 5, + rent: 5000, + seller: sellerId + }); +} + +export { evalPopulate }; diff --git a/be/src/helpers/server.js b/be/src/helpers/server.js index 495cb75..857faa9 100644 --- a/be/src/helpers/server.js +++ b/be/src/helpers/server.js @@ -1,11 +1,14 @@ import { crs, exp, pth, url } from "./imports.js"; import { connectDatabase } from "./database.js"; +import { evalPopulate } from "./populate.js"; import { apiRouter } from "./routers.js"; const startServer = () => { const app = exp(); + const isEval = process.env.IS_EVAL; + const serverPort = process.env.SERVER_PORT; const staticDir = pth.join(pth.dirname(url.fileURLToPath(import.meta.url)), "../../../fe/build"); @@ -32,7 +35,13 @@ const startServer = () => { res.sendFile(`${staticDir}/index.html`) }); - connectDatabase().then(() => {}); + connectDatabase().then(() => { + if (isEval === 'true') { + evalPopulate().then(() => { + console.log('[server] Populated database with sample data for evaluation'); + }); + } + }); app.listen(serverPort, () => { console.log(`[server] Listening on port ${serverPort}`); From 44c12ad90799846e867f975af7dedc9d6437ab46 Mon Sep 17 00:00:00 2001 From: SomesH S Date: Tue, 28 May 2024 06:43:32 +0000 Subject: [PATCH 13/36] refactor Dockerfile --- Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4364485..6e325cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,10 @@ FROM node:current-bullseye-slim as fe RUN corepack enable WORKDIR /root/fe -COPY ./fe . +COPY ./fe/package.json . +COPY ./fe/yarn.lock . RUN yarn install +COPY ./fe . RUN yarn produce FROM mongo:latest as fs @@ -14,9 +16,12 @@ RUN apt-get update && \ corepack enable COPY --from=sssomeshhh/rentify:fe /root/fe/build /root/fe/build WORKDIR /root/be -COPY ./be . +COPY ./be/package.json . +COPY ./be/yarn.lock . RUN yarn install +COPY ./be . ENV SERVER_PORT=80 EXPOSE 80 +ENV IS_EVAL=true RUN echo "mongod > /dev/null 2>&1 & disown ; yarn produce ;" > startApp CMD bash ./startApp From 22d7acb088a581744fb6de67be4b600159ce64c5 Mon Sep 17 00:00:00 2001 From: SomesH S Date: Tue, 28 May 2024 06:44:32 +0000 Subject: [PATCH 14/36] remove be.xml --- .idea/runConfigurations/be.xml | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .idea/runConfigurations/be.xml diff --git a/.idea/runConfigurations/be.xml b/.idea/runConfigurations/be.xml deleted file mode 100644 index d49b878..0000000 --- a/.idea/runConfigurations/be.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - \ No newline at end of file From 719db802b1050fa8079cba3cf826d4251f67b0a9 Mon Sep 17 00:00:00 2001 From: SomesH S Date: Tue, 28 May 2024 06:45:33 +0000 Subject: [PATCH 15/36] fe.xml - remove buildArgs, contextFolderPath --- .idea/runConfigurations/fe.xml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.idea/runConfigurations/fe.xml b/.idea/runConfigurations/fe.xml index d93820d..88b6f6c 100644 --- a/.idea/runConfigurations/fe.xml +++ b/.idea/runConfigurations/fe.xml @@ -3,17 +3,8 @@ From cd091ad0630f750bdd905985984d81a3820b897b Mon Sep 17 00:00:00 2001 From: SomesH S Date: Tue, 28 May 2024 06:46:48 +0000 Subject: [PATCH 16/36] xx.xml - remove ' --progress plain' --- .idea/runConfigurations/fe.xml | 2 +- .idea/runConfigurations/fs.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/runConfigurations/fe.xml b/.idea/runConfigurations/fe.xml index 88b6f6c..2301b47 100644 --- a/.idea/runConfigurations/fe.xml +++ b/.idea/runConfigurations/fe.xml @@ -3,7 +3,7 @@ diff --git a/.idea/runConfigurations/fs.xml b/.idea/runConfigurations/fs.xml index 47522d7..8e9cd00 100644 --- a/.idea/runConfigurations/fs.xml +++ b/.idea/runConfigurations/fs.xml @@ -3,7 +3,7 @@