Compare commits
2 Commits
main
...
vikas_16_d
Author | SHA1 | Date | |
---|---|---|---|
8fc9cc2d2d | |||
0ad38baa99 |
@ -21,5 +21,9 @@ RUN npm run build # This will run tsc -b and vite build
|
||||
# Expose the port the app will use
|
||||
EXPOSE 4173
|
||||
|
||||
# Copy the entrypoint script
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
# Start the app using the preview server
|
||||
CMD ["npm", "run", "preview"]
|
||||
|
7
entrypoint.sh
Normal file
7
entrypoint.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Create a JavaScript file with environment variables
|
||||
echo "window._env_ = { VITE_API_URL: \"$VITE_API_URL\" };" > /app/dist/env.js
|
||||
|
||||
# Start the Vite preview server
|
||||
exec "$@"
|
@ -47,6 +47,8 @@
|
||||
<script src="/assets/vendor/js/helpers.js"></script>
|
||||
<script src="/assets/js/config.js"></script>
|
||||
|
||||
<script src="/env.js"></script>
|
||||
|
||||
<!-- Timer Picker -->
|
||||
<!-- Flatpickr CSS -->
|
||||
|
||||
|
@ -25,8 +25,9 @@ const LoginPage = () => {
|
||||
}));
|
||||
};
|
||||
|
||||
const handleSubmit = async ( e ) =>
|
||||
{
|
||||
const handleSubmit = async (e) => {
|
||||
console.log(window._env_?.VITE_API_URL);
|
||||
console.log(import.meta.env.VITE_API_URL);
|
||||
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
@ -45,7 +46,6 @@ const LoginPage = () => {
|
||||
} catch (err) {
|
||||
console.log("Unable to proceed. Please try again.");
|
||||
setLoading(false);
|
||||
|
||||
}
|
||||
};
|
||||
return (
|
||||
|
@ -2,9 +2,12 @@ import axios from "axios";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import axiosRetry from "axios-retry";
|
||||
import showToast from "../services/toastService";
|
||||
const base_Url = process.env.VITE_BASE_URL;
|
||||
|
||||
const API_URL = window._env_?.VITE_API_URL || import.meta.env.VITE_API_URL;
|
||||
|
||||
console.log("API_URL" + API_URL);
|
||||
export const axiosClient = axios.create({
|
||||
baseURL: base_Url, // Your Web API URL
|
||||
baseURL: API_URL, // Your Web API URL
|
||||
withCredentials: false, // Required if the API uses cookies
|
||||
headers: {
|
||||
"Content-Type": "application/json", // Specify the content type
|
||||
@ -16,6 +19,8 @@ axiosRetry(axiosClient, { retries: 3 });
|
||||
// Request interceptor to add Bearer token
|
||||
axiosClient.interceptors.request.use(
|
||||
async (config) => {
|
||||
console.log("Starting Request", JSON.stringify(config, null, 2));
|
||||
console.log("API_URL", API_URL);
|
||||
if (config.authRequired) {
|
||||
const token = localStorage.getItem("jwtToken");
|
||||
if (token) {
|
||||
@ -44,17 +49,29 @@ axiosClient.interceptors.response.use(
|
||||
originalRequest._toastShown = true;
|
||||
|
||||
if (error.code === "ERR_CONNECTION_REFUSED") {
|
||||
console.error("Connection refused. Please ensure the server is running.");
|
||||
showToast("Unable to connect to the server. Please try again later.", "error");
|
||||
console.error(
|
||||
"Connection refused. Please ensure the server is running."
|
||||
);
|
||||
showToast(
|
||||
"Unable to connect to the server. Please try again later.",
|
||||
"error"
|
||||
);
|
||||
} else if (error.code === "ERR_NETWORK") {
|
||||
console.error("Network error: Unable to reach the server.");
|
||||
showToast("Server is unreachable. Try again later!", "error");
|
||||
redirectToLogin();
|
||||
} else if (error.code === "ECONNABORTED") {
|
||||
console.error("Request timed out.");
|
||||
showToast("The request took too long. Please try again later.", "error");
|
||||
showToast(
|
||||
"The request took too long. Please try again later.",
|
||||
"error"
|
||||
);
|
||||
} else if (error.response) {
|
||||
console.error("Error response:", error.response.status, error.response.data);
|
||||
console.error(
|
||||
"Error response:",
|
||||
error.response.status,
|
||||
error.response.data
|
||||
);
|
||||
|
||||
if (error.response.status === 401 && !originalRequest._retry) {
|
||||
originalRequest._retry = true;
|
||||
@ -90,7 +107,11 @@ axiosClient.interceptors.response.use(
|
||||
return Promise.reject(err);
|
||||
}
|
||||
} else {
|
||||
showToast(error.response.data?.message || "An error occurred. Please try again.", "error");
|
||||
showToast(
|
||||
error.response.data?.message ||
|
||||
"An error occurred. Please try again.",
|
||||
"error"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.error("An unknown error occurred:", error.message);
|
||||
|
Loading…
x
Reference in New Issue
Block a user