Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge phca with trunk #1

Merged
merged 37 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dd6a9d3
merge serverapi.js, serverweb.js as server.js
sssomeshhh May 27, 2024
fa034c8
database.js - connectDB -> connectDatabase
sssomeshhh May 27, 2024
441c933
Dockerfile - add env SERVER_PORT=80 and update EXPOSE
sssomeshhh May 27, 2024
d995fb8
remove typo in PropertyList.js
sssomeshhh May 27, 2024
b1b4019
'window.location' -> 'location.'
sssomeshhh May 27, 2024
5a1a2da
'location' -> 'location.pathname' in handleSubmit in PropertyDetail.js
sssomeshhh May 27, 2024
cb5fef2
fix views in PropertyDetail
sssomeshhh May 27, 2024
5206421
remove be target and refactor
sssomeshhh May 27, 2024
15a030c
Dockerfile - rearrange steps
sssomeshhh May 27, 2024
88707c0
Login - add alert for error in handleLogin
sssomeshhh May 27, 2024
0c32fdc
Register - redirect to Login when successful
sssomeshhh May 27, 2024
5032c2a
add evalPopulate()
sssomeshhh May 28, 2024
44c12ad
refactor Dockerfile
sssomeshhh May 28, 2024
22d7acb
remove be.xml
sssomeshhh May 28, 2024
719db80
fe.xml - remove buildArgs, contextFolderPath
sssomeshhh May 28, 2024
cd091ad
xx.xml - remove ' --progress plain'
sssomeshhh May 28, 2024
d55c018
fs.xml - remove 8080 PortBinding
sssomeshhh May 28, 2024
fe67a51
add webpack, webpack-cli to package.json, yarn.lock
sssomeshhh May 28, 2024
9f6bb03
add webpack.config.js
sssomeshhh May 28, 2024
ec0fc7a
add sea.json
sssomeshhh May 28, 2024
2b04b85
remove .env
sssomeshhh May 28, 2024
64cf04c
yarn produce => yarn webpack
sssomeshhh May 28, 2024
53b200f
webpack.config.js - add output.filename
sssomeshhh May 28, 2024
8fe814e
Merge branch 'refs/heads/trunk' into phca
sssomeshhh May 28, 2024
e17087c
move 'yarn produce' to target 'xe'
sssomeshhh May 28, 2024
e7ded6f
fe.xml - add buildArgs, contextFolder
sssomeshhh May 28, 2024
3ba401a
add be.xml
sssomeshhh May 28, 2024
6915c33
update workflow for target be
sssomeshhh May 28, 2024
8eaaac2
update 'COPY --from' in target 'fs'
sssomeshhh May 28, 2024
7c59f5e
sea.json - 'main.cjs' -> 'fs.cjs'
sssomeshhh May 28, 2024
84899c5
sea.json - 'sea.blob' -> 'fs.blob'
sssomeshhh May 28, 2024
bdb5dc2
update targets be, fs and add target rn
sssomeshhh May 28, 2024
5c8cfe7
update workflow for target rn
sssomeshhh May 28, 2024
3fcd705
server.js - use environment variable for 'staticDir'
sssomeshhh May 28, 2024
e2cd2fb
imports.js - remove pth, ses, url
sssomeshhh May 28, 2024
3977f63
package.json - remove express-session
sssomeshhh May 28, 2024
7c8b0b5
refactor Dockerfile for STATIC_DIR environment variable
sssomeshhh May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,35 @@ jobs:
tags: |
sssomeshhh/rentify:fs
sssomeshhh/rentify:fs-${{ github.sha }}

rn:
runs-on: ubuntu-22.04
needs: fs
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/[email protected]
with:
registry: docker.io
username: sssomeshhh
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Setup Docker Buildx
id: setup_buildx
uses: docker/[email protected]
- name: Build Target
uses: docker/[email protected]
with:
builder: ${{ steps.setup_buildx.name }}
context: .
file: Dockerfile
target: rn
cache-from: |
type=registry,ref=sssomeshhh/cache:rentify-rn
cache-to: |
type=registry,ref=sssomeshhh/cache:rentify-rn
load: false
push: true
tags: |
sssomeshhh/rentify:rn
sssomeshhh/rentify:rn-${{ github.sha }}
2 changes: 1 addition & 1 deletion .idea/runConfigurations/be.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/fe.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions .idea/runConfigurations/fs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ COPY package.json .
COPY yarn.lock .
RUN yarn install
COPY . .

FROM xe as be
RUN yarn produce

FROM xe as fe
RUN yarn produce

FROM xe as be
RUN mv dist/fs.cjs ./ && \
node --experimental-sea-config sea.json && \
cp /usr/local/bin/node ./fs && \
npx postject fs NODE_SEA_BLOB fs.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2

FROM ubuntu:noble as fs
WORKDIR /root/fs
COPY --from=be /root/be/ .
COPY --from=fe /root/fe/ .
COPY --from=sssomeshhh/rentify:be /root/be/fs .
COPY --from=sssomeshhh/rentify:fe /root/fe/build ./static
ENV NODE_NO_WARNINGS=1 IS_EVAL=true SERVER_PORT=80 STATIC_DIR=/root/fs/static
CMD ./fs

FROM mongo:latest as rn
WORKDIR /root/rn
COPY --from=sssomeshhh/rentify:fs /root/fs .
ENV NODE_NO_WARNINGS=1 IS_EVAL=true SERVER_PORT=80 STATIC_DIR=/root/rn/static
RUN echo "mongod > /dev/null 2>&1 & disown ; ./fs ;" > stRn
CMD bash ./stRn
2 changes: 0 additions & 2 deletions be/.env

This file was deleted.

8 changes: 4 additions & 4 deletions be/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
"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",
"mongoose": "^8.4.0"
},
"devDependencies": {
"nodemon": "^3.1.0"
"nodemon": "^3.1.0",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
},
"main": "index.js",
"scripts": {
"develop": "nodemon src/index.js",
"produce": "node src/index.js"
"produce": "yarn webpack"
},
"packageManager": "[email protected]"
}
4 changes: 4 additions & 0 deletions be/sea.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "fs.cjs",
"output": "fs.blob"
}
6 changes: 3 additions & 3 deletions be/src/helpers/database.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {mng} from "./imports.js";

const connect = async () => {
const connectDatabase = 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);
}
};

export { connect };
export { connectDatabase };
11 changes: 0 additions & 11 deletions be/src/helpers/environment.js

This file was deleted.

10 changes: 1 addition & 9 deletions be/src/helpers/imports.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
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";
import pth from "path";
import ses from "express-session";
import url from "url";

export {
bcr,
crs,
cry,
env,
exp,
jwt,
mng,
pth,
ses,
url
mng
};
71 changes: 71 additions & 0 deletions be/src/helpers/populate.js
Original file line number Diff line number Diff line change
@@ -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: '[email protected]',
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: '[email protected]',
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 };
12 changes: 6 additions & 6 deletions be/src/helpers/routers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
51 changes: 51 additions & 0 deletions be/src/helpers/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { crs, exp } 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 = process.env.STATIC_DIR;

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`)
});

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}`);
});
};

export { startServer };
23 changes: 0 additions & 23 deletions be/src/helpers/serverapi.js

This file was deleted.

Loading