Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 16 additions & 1 deletion apps/OpenSign/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState, useEffect } from "react";
import { lazyWithRetry, hideUpgradeProgress } from "./utils";
import { Routes, Route, BrowserRouter } from "react-router";
import { getEnv } from "./constant/Utils";
import { pdfjs } from "react-pdf";
import Form from "./pages/Form";
import Report from "./pages/Report";
Expand Down Expand Up @@ -62,7 +63,21 @@ function App() {
{isloading ? (
<AppLoader />
) : (
<BrowserRouter>
<BrowserRouter basename={(() => {
try {
// import.meta.env.BASE_URL always reflects the Vite base, so a
// build-time PUBLIC_URL reaches the router too.
const raw =
getEnv()?.PUBLIC_URL ||
process.env.PUBLIC_URL ||
import.meta.env.BASE_URL;
if (raw) {
const u = new URL(raw, window.location.origin);
return u.pathname.replace(/\/$/, "") || "/";
}
} catch (e) { /* ignore */ }
return "/";
})()}>
<Title />
<Routes>
<Route element={<ValidateRoute />}>
Expand Down
27 changes: 18 additions & 9 deletions apps/OpenSign/src/pages/PdfRequestFiles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,25 @@ function PdfRequestFiles(
sendmail = getQuery?.[1]?.split("=")[1]; //false
}

const routeId = route && route?.split("/"); // ['', 'load', 'recipientSignPdf', ':docId', ':contactBookId']
if (routeId && routeId.length > 4) {
// this condition will be occur only in guest flow in which load routeId will be include
isGuestSignFlow = true;
getDocId = routeId[3];
contactBookId = routeId[4];
// The app can be deployed under a sub-path, so the base has to be removed
// before the route is parsed and the segments are located by name.
const deploymentBase = (import.meta.env.BASE_URL || "/").replace(/\/$/, "");
const routePath =
deploymentBase && route.startsWith(deploymentBase)
? route.slice(deploymentBase.length)
: route;
const routeId = routePath.split("/").filter(Boolean);
const signRouteIndex = routeId.indexOf("recipientSignPdf");
if (signRouteIndex !== -1) {
// guest flow: /load/recipientSignPdf/:docId/:contactBookId
isGuestSignFlow =
signRouteIndex > 0 && routeId.slice(0, signRouteIndex).includes("load");
getDocId = routeId[signRouteIndex + 1] || "";
contactBookId = routeId[signRouteIndex + 2] || "";
} else {
// this condition will be occur only in if user is logged in and load routeId will be exclude
getDocId = routeId[2];
contactBookId = routeId?.[3] || "";
// fallback that keeps the previous indexing for unknown shapes
getDocId = routeId[1] || "";
contactBookId = routeId[2] || "";
}
let getDocumentId =
getDocId ||
Expand Down
13 changes: 13 additions & 0 deletions apps/OpenSign/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@ export default defineConfig(({ mode }) => {
// Load ALL env vars (no prefix filter)
const env = loadEnv(mode, process.cwd(), "");

// Normalize PUBLIC_URL into a base path for Vite
let basePath = "/";
try {
const raw = env.PUBLIC_URL || process.env.PUBLIC_URL;
if (raw) {
const u = new URL(raw, "http://localhost");
basePath = u.pathname.endsWith("/") ? u.pathname : u.pathname + "/";
}
} catch (e) {
// ignore
}

return {
plugins: [
react(),
svgr() // Transform SVGs into React components
],
base: basePath,
resolve: { alias: {} }, // Add any necessary aliases here
define: {
// Replace process.env.REACT_APP_* with import.meta.env.VITE_*
Expand Down