Skip to content

Commit

Permalink
Merge pull request #1 from sssomeshhh/phca
Browse files Browse the repository at this point in the history
merge phca with trunk
  • Loading branch information
sssomeshhh authored May 28, 2024
2 parents 972ed29 + 7c8b0b5 commit a23bf9f
Show file tree
Hide file tree
Showing 26 changed files with 1,328 additions and 242 deletions.
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

0 comments on commit a23bf9f

Please sign in to comment.