Skip to content

Commit f19f743

Browse files
committed
added domain name
2 parents a00758d + fcbc3ec commit f19f743

File tree

15 files changed

+642
-516
lines changed

15 files changed

+642
-516
lines changed

backend/controllers/userController.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ exports.registerUser = catchAsyncErrors(async (req, res, next) => {
1010
const { name, email, password } = req.body;
1111
// console.log(req);
1212
const { originalname, path, mimetype } = req.file;
13-
console.log("file name : ",originalname);
14-
console.log("file path: ",path);
15-
console.log("file type: ",mimetype);
13+
console.log("file name : ", originalname);
14+
console.log("file path: ", path);
15+
console.log("file type: ", mimetype);
1616

1717
const user = await User.create({
1818
name,
@@ -106,8 +106,13 @@ exports.forgotPassword = catchAsyncErrors(async (req, res, next) => {
106106
const resetToken = user.getResetPasswordToken();
107107

108108
await user.save({ validateBeforeSave: false });
109-
110-
const resetPasswordUrl = `${req.protocol}://localhost:3000/resetpassword/${resetToken}`;
109+
let url;
110+
if (process.env.NODE_ENV !== "PRODUCTION") {
111+
url = `${process.env.CLIENT_URL}/resetpassword/${resetToken}`;
112+
} else {
113+
url = `${req.protocol}://localhost:3000/resetpassword/${resetToken}`;
114+
}
115+
const resetPasswordUrl = url;
111116
// console.log(resetPasswordUrl);
112117
const text = `Your password reset token is :- \n\n ${resetPasswordUrl} \n\nIf you have not requested this email then, please ignore it.`;
113118
// console.log(user.email);
@@ -293,5 +298,3 @@ const fileSizeFormatter = (bytes, decimal) => {
293298
parseFloat((bytes / Math.pow(1000, index)).toFixed(dm)) + " " + sizes[index]
294299
);
295300
};
296-
297-

backend/index.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,40 @@ const socketServer = require("./socketServer");
99
const errorMiddleware = require("./middleware/error");
1010
const dotenv = require("dotenv");
1111
// Config
12-
if (process.env.NODE_ENV !== "PRODUCTION") {
13-
require("dotenv").config({ path: "./secret.env" });
14-
}
12+
// if (process.env.NODE_ENV !== "PRODUCTION") {
13+
require("dotenv").config({ path: "./secret.env" });
14+
// }
1515

1616
console.log(process.env.SMPT_MAIL);
1717

1818
app.use(express.json());
1919
app.use(cookieParser());
2020
app.use(bodyParser.urlencoded({ extended: true }));
21-
const temp = process.env.CLIENT_URL || "http://localhost:3000";
2221
app.use(
2322
cors({
24-
origin: "http://localhost:3000",
23+
origin: [
24+
"http://localhost:3000",
25+
"https://recruitingwebsite.online",
26+
"https://www.recruitingwebsite.online",
27+
],
2528
credentials: true,
2629
})
2730
);
31+
2832
// Route Imports
2933

3034

31-
app.get('/', (req, res) => {
35+
app.get('/',(req,res)=>{
3236
res.send("Recruitify Api is working fine");
33-
})
34-
37+
});
3538

3639
const user = require("./routes/userRoute");
3740
const group = require("./routes/groupRoutes");
3841
const friendInvitationRoutes = require("./routes/friendInvitationRoutes");
3942

4043
const posts = require("./routes/postRouter");
41-
const jobs = require('./routes/jobsRouter');
42-
const profile = require('./routes/profileRouter');
43-
44+
const jobs = require("./routes/jobsRouter");
45+
const profile = require("./routes/profileRouter");
4446

4547
app.use("/api/v1", user);
4648
app.use("/api/v1", group);
@@ -71,14 +73,10 @@ process.on("uncaughtException", (err) => {
7173
process.exit(1);
7274
});
7375

74-
// Config
75-
if (process.env.NODE_ENV !== "PRODUCTION") {
76-
require("dotenv").config({ path: "./config.env" });
77-
}
78-
79-
// Connecting to database
80-
connectDatabase();
81-
76+
+(
77+
// Connecting to database
78+
connectDatabase()
79+
);
8280

8381
const server = http.createServer(app);
8482

@@ -88,9 +86,9 @@ socketServer.registerSocketServer(server);
8886
server.listen(process.env.PORT, () => {
8987
console.log(`Server is working on http://localhost:${process.env.PORT}`);
9088

91-
process.on("unhandledRejection", (err) => {
92-
console.log(`Error: ${err.message}`);
93-
console.log(`Shutting down the server due to Unhandled Promise Rejection`);
89+
process.on("unhandledRejection", (err) => {
90+
console.log(`Error: ${err.message}`);
91+
console.log(`Shutting down the server due to Unhandled Promise Rejection`);
9492

9593
server.close(() => {
9694
process.exit(1);

backend/socketServer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ const groupChatHistoryHandler = require("./socketHandlers/groupChatHistoryHandle
1313
const serverStore = require("./serverStore");
1414

1515
const registerSocketServer = (server) => {
16+
let url;
17+
1618
const io = require("socket.io")(server, {
1719
cors: {
18-
origin: "http://localhost:3000",
20+
origin: [
21+
"http://localhost:3000",
22+
"https://recruitingwebsite.online",
23+
"https://www.recruitingwebsite.online",
24+
],
1925
credentials: true,
2026
methods: ["GET", "POST"],
2127
},
2228
});
23-
const temp = process.env.CLIENT_URL || "http://localhost:3000";
24-
console.log("client URl == "+ temp);
2529

2630
serverStore.setSocketServerInstance(io);
2731

backend/utils/jwtToken.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const sendToken = (user, statusCode, res) => {
1111
maxAge: 1000 * 60 * 60 * 24,
1212
httpOnly: true,
1313
sameSite: "lax",
14-
secure: false,
14+
secure: process.env.NODE_ENV === "PRODUCTION" ? true : false,
1515
};
1616

1717
res.status(statusCode).cookie("token", token, options).json({

frontend/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REACT_APP_BACKEND_URL = http://localhost:4000
2+
REACT_APP_ENVIRONMENT = DEVELOPMENT

frontend/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414

1515
# misc
16-
/secret.env
16+
/.env
1717
/frontend/.DS_Store
18+
/frontend/.env
1819
/frontend/.env.local
1920
/frontend/.env.development.local
2021
/frontend/.env.test.local

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "frontend",
33
"version": "0.1.0",
44
"private": true,
5-
"proxy": "https://api.recruitingwebsite.online",
5+
"proxy": "https://localhost:4000",
66
"dependencies": {
77
"@chakra-ui/icons": "^2.1.1",
88
"@chakra-ui/react": "^2.8.2",

frontend/public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta name="theme-color" content="#000000" />
88
<meta
99
name="description"
10-
content="Web site created using create-react-app"
10+
content="Recruitify"
1111
/>
1212
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
1313
<!--
@@ -24,7 +24,7 @@
2424
work correctly both with client-side routing and a non-root public URL.
2525
Learn how to configure a non-root public URL by running `npm run build`.
2626
-->
27-
<title>Chat App</title>
27+
<title>Recruitify</title>
2828
</head>
2929
<body>
3030
<noscript>You need to enable JavaScript to run this app.</noscript>

frontend/src/api.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import axios from "axios";
2+
axios.defaults.baseURL = process.env.REACT_APP_BACKEND_URL;
23
// import { logout } from "./shared/utils/auth";
34

45
// const apiClient = axios.create({
@@ -47,6 +48,8 @@ import axios from "axios";
4748
// };
4849

4950
// secure routes
51+
52+
const base_url = process.env.REACT_APP_BACKEND_URL;
5053
export const sendFriendInvitation = async (data) => {
5154
try {
5255
const config = {
@@ -154,7 +157,7 @@ export const getGroup = async () => {
154157
// };
155158

156159
const api = axios.create({
157-
baseURL: '/api',
160+
baseURL: "/api",
158161
});
159162

160163
export default api;

frontend/src/features/auth/authActions.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios from "axios";
22
import { createAsyncThunk } from "@reduxjs/toolkit";
33
import { useDispatch } from "react-redux";
4+
const base_url = process.env.REACT_APP_BACKEND_URL;
45

56
export const userLogin = createAsyncThunk(
67
"user/login",
@@ -13,7 +14,7 @@ export const userLogin = createAsyncThunk(
1314
};
1415

1516
const { data } = await axios.post(
16-
`/api/v1/login`,
17+
`${base_url}/api/v1/login`,
1718
{ email, password },
1819
{ withCredentials: true },
1920
config
@@ -42,7 +43,7 @@ export const registerUser = createAsyncThunk(
4243
},
4344
};
4445
const { data } = await axios.post(
45-
`/api/v1/register`,
46+
`${base_url}/api/v1/register`,
4647
{ name, email, password, file },
4748
{
4849
headers: {
@@ -66,7 +67,7 @@ export const registerUser = createAsyncThunk(
6667

6768
export const logout = createAsyncThunk("user/logout", async (thunkAPI) => {
6869
try {
69-
await axios.get(`/api/v1/logout`);
70+
await axios.get(`${base_url}/api/v1/logout`);
7071
} catch (error) {
7172
thunkAPI.dispatch({ payload: error.message });
7273
}
@@ -76,7 +77,9 @@ export const profile = createAsyncThunk(
7677
"user/profile",
7778
async (rejectWithValue) => {
7879
try {
79-
const { data } = await axios.get(`/api/v1/me`, { withCredentials: true });
80+
const { data } = await axios.get(`${base_url}/api/v1/me`, {
81+
withCredentials: true,
82+
});
8083
return data;
8184
} catch (error) {
8285
if (error.response && error.response.data.message) {
@@ -93,7 +96,7 @@ export const updateProfile = createAsyncThunk(
9396
async ({ name, email, password, file }, { rejectWithValue }) => {
9497
try {
9598
const success = await axios.put(
96-
`/api/v1/me/update`,
99+
`${base_url}/api/v1/me/update`,
97100
{ name, email, password, file },
98101
{
99102
headers: {
@@ -126,7 +129,7 @@ export const passwordUpdate = createAsyncThunk(
126129
},
127130
};
128131
const { data } = await axios.put(
129-
`/api/v1/password/update`,
132+
`${base_url}/api/v1/password/update`,
130133
{ oldPassword, confirmPassword, newPassword },
131134
{ withCredentials: true },
132135
config
@@ -151,7 +154,7 @@ export const passwordForgot = createAsyncThunk(
151154
},
152155
};
153156
const { data } = await axios.post(
154-
`/api/v1/password/forgot`,
157+
`${base_url}/api/v1/password/forgot`,
155158
{ email },
156159

157160
{ withCredentials: true },
@@ -177,7 +180,7 @@ export const passwordReset = createAsyncThunk(
177180
},
178181
};
179182
const { data } = await axios.put(
180-
`/api/v1/password/reset/${token}`,
183+
`${base_url}/api/v1/password/reset/${token}`,
181184
{ newPassword, confirmPassword, token },
182185
{ withCredentials: true },
183186
config

frontend/src/realtimeCommunication/socketConnection.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ let socket = null;
1717

1818
export const connectWithSocketServer = (userInfo) => {
1919
const jwtToken = userInfo.token;
20-
const connection_url = "https://api.recruitingwebsite.online/"
20+
21+
22+
const connection_url =
23+
process.env.REACT_APP_ENVIRONMENT == "PRODUCTION"
24+
? process.env.REACT_APP_BACKEND_URL
25+
: "http://localhost:4000";
26+
// Update this URL with your server's local network IP
2127
socket = io(
2228
connection_url,
2329
{

frontend/src/store/actions/friendsActions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { openAlertMessage } from "./alertActions";
22
import * as api from "../../api";
33
import axios from "axios";
4+
axios.defaults.baseURL = "https://api.recruitingwebsite.online";
45
export const friendsActions = {
56
SET_FRIENDS: "FRIENDS.SET_FRIENDS",
67
SET_PENDING_FRIENDS_INVITATIONS: "FRIENDS.SET_PENDING_FRIENDS_INVITATIONS",

0 commit comments

Comments
 (0)