Skip to content

Commit d6803c5

Browse files
committed
deployment added
1 parent a2bfc23 commit d6803c5

File tree

7 files changed

+41
-33
lines changed

7 files changed

+41
-33
lines changed

backend/index.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,18 @@ console.log(process.env.SMPT_MAIL);
1818
app.use(express.json());
1919
app.use(cookieParser());
2020
app.use(bodyParser.urlencoded({ extended: true }));
21-
if (process.env.NODE_ENV === "PRODUCTION") {
22-
app.use(
23-
cors({
24-
origin: "process.env.CLIENT_URL",
25-
credentials: true,
26-
})
27-
);
28-
} else {
29-
app.use(
30-
cors({
31-
origin: "http://localhost:3000",
32-
credentials: true,
33-
})
34-
);
35-
}
21+
22+
app.use(
23+
cors({
24+
origin: [
25+
"http://localhost:3000",
26+
"https://recruitingwebsite.online",
27+
"https://www.recruitingwebsite.online",
28+
],
29+
credentials: true,
30+
})
31+
);
32+
3633
// Route Imports
3734

3835
app.get("/", (req, res) => {

backend/socketServer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ const serverStore = require("./serverStore");
1414

1515
const registerSocketServer = (server) => {
1616
let url;
17-
if (process.env.NODE_ENV === "PRODUCTION") {
18-
url = "process.env.CLIENT_URL";
19-
} else {
20-
url = "http://localhost:3000";
21-
}
17+
2218
const io = require("socket.io")(server, {
2319
cors: {
24-
origin: url,
20+
origin: [
21+
"http://localhost:3000",
22+
"https://recruitingwebsite.online",
23+
"https://www.recruitingwebsite.online",
24+
],
2525
credentials: true,
2626
methods: ["GET", "POST"],
2727
},

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+
BACKEND_URL = "https://api.recruitingwebsite.online/"
2+
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/src/features/auth/authActions.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import axios from "axios";
22
import { createAsyncThunk } from "@reduxjs/toolkit";
33
import { useDispatch } from "react-redux";
4-
4+
const base_url =
5+
process.env.NODE_ENV == "PRODUCTION"
6+
? process.env.BACKEND_URL
7+
: "http://localhost:4000";
58
export const userLogin = createAsyncThunk(
69
"user/login",
710
async ({ email, password }, { rejectWithValue }) => {
@@ -13,7 +16,7 @@ export const userLogin = createAsyncThunk(
1316
};
1417

1518
const { data } = await axios.post(
16-
`/api/v1/login`,
19+
`${base_url}/api/v1/login`,
1720
{ email, password },
1821
{ withCredentials: true },
1922
config
@@ -42,7 +45,7 @@ export const registerUser = createAsyncThunk(
4245
},
4346
};
4447
const { data } = await axios.post(
45-
`/api/v1/register`,
48+
`${base_url}/api/v1/register`,
4649
{ name, email, password, file },
4750
{
4851
headers: {
@@ -66,7 +69,7 @@ export const registerUser = createAsyncThunk(
6669

6770
export const logout = createAsyncThunk("user/logout", async (thunkAPI) => {
6871
try {
69-
await axios.get(`/api/v1/logout`);
72+
await axios.get(`${base_url}/api/v1/logout`);
7073
} catch (error) {
7174
thunkAPI.dispatch({ payload: error.message });
7275
}
@@ -76,7 +79,9 @@ export const profile = createAsyncThunk(
7679
"user/profile",
7780
async (rejectWithValue) => {
7881
try {
79-
const { data } = await axios.get(`/api/v1/me`, { withCredentials: true });
82+
const { data } = await axios.get(`${base_url}/api/v1/me`, {
83+
withCredentials: true,
84+
});
8085
return data;
8186
} catch (error) {
8287
if (error.response && error.response.data.message) {
@@ -93,7 +98,7 @@ export const updateProfile = createAsyncThunk(
9398
async ({ name, email, password, file }, { rejectWithValue }) => {
9499
try {
95100
const success = await axios.put(
96-
`/api/v1/me/update`,
101+
`${base_url}/api/v1/me/update`,
97102
{ name, email, password, file },
98103
{
99104
headers: {
@@ -126,7 +131,7 @@ export const passwordUpdate = createAsyncThunk(
126131
},
127132
};
128133
const { data } = await axios.put(
129-
`/api/v1/password/update`,
134+
`${base_url}/api/v1/password/update`,
130135
{ oldPassword, confirmPassword, newPassword },
131136
{ withCredentials: true },
132137
config
@@ -151,7 +156,7 @@ export const passwordForgot = createAsyncThunk(
151156
},
152157
};
153158
const { data } = await axios.post(
154-
`/api/v1/password/forgot`,
159+
`${base_url}/api/v1/password/forgot`,
155160
{ email },
156161

157162
{ withCredentials: true },
@@ -177,7 +182,7 @@ export const passwordReset = createAsyncThunk(
177182
},
178183
};
179184
const { data } = await axios.put(
180-
`/api/v1/password/reset/${token}`,
185+
`${base_url}/api/v1/password/reset/${token}`,
181186
{ newPassword, confirmPassword, token },
182187
{ withCredentials: true },
183188
config

frontend/src/realtimeCommunication/socketConnection.js

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

1818
export const connectWithSocketServer = (userInfo) => {
1919
const jwtToken = userInfo.token;
20-
const connection_url = "https://api.recruitingwebsite.online/";
20+
const connection_url =
21+
process.env.ENVIRONMENT == "PRODUCTION"
22+
? process.env.BACKEND_URL
23+
: "http://localhost:4000";
2124
// Update this URL with your server's local network IP
2225
socket = io(
2326
connection_url,

0 commit comments

Comments
 (0)