Skip to content

Commit 53d278a

Browse files
dvaldiviaBenjamin Perez
andauthored
Define base for assets and support for sub path (#1247)
* Added correct mime type to files * Define Base for Assets Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> * lint Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> * Make things relative Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> * hop styling Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 820fa61 commit 53d278a

File tree

11 files changed

+166
-121
lines changed

11 files changed

+166
-121
lines changed

operatorapi/proxy.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
185185
responseWriter.WriteHeader(500)
186186
return
187187
}
188-
targetURL.Path = strings.Replace(req.URL.Path, fmt.Sprintf("/api/proxy/%s/%s", tenant.Namespace, tenant.Name), "", -1)
188+
tenantBase := fmt.Sprintf("/api/proxy/%s/%s", tenant.Namespace, tenant.Name)
189+
targetURL.Path = strings.Replace(req.URL.Path, tenantBase, "", -1)
189190

190191
proxiedCookie := &http.Cookie{
191192
Name: "token",
@@ -207,8 +208,17 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
207208
CheckRedirect: func(req *http.Request, via []*http.Request) error {
208209
return http.ErrUseLastResponse
209210
}}
211+
212+
// are we proxying something with cp=y? (console proxy) then add cpb (console proxy base) so the console
213+
// on the other side updates the <base href="" /> to this value overriding sub path or root
214+
if v := req.URL.Query().Get("cp"); v == "y" {
215+
q := req.URL.Query()
216+
q.Add("cpb", tenantBase)
217+
req.URL.RawQuery = q.Encode()
218+
}
210219
// copy query params
211220
targetURL.RawQuery = req.URL.Query().Encode()
221+
212222
proxRequest, err := http.NewRequest(req.Method, targetURL.String(), req.Body)
213223
if err != nil {
214224
log.Println(err)

portal-ui/public/index.html

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,52 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1" />
5+
<base href="/" />
6+
<meta content="width=device-width, initial-scale=1" name="viewport" />
67
<meta
7-
name="theme-color"
88
content="#081C42"
99
media="(prefers-color-scheme: light)"
10+
name="theme-color"
1011
/>
1112
<meta
12-
name="theme-color"
1313
content="#081C42"
1414
media="(prefers-color-scheme: dark)"
15+
name="theme-color"
1516
/>
16-
<meta name="description" content="MinIO Console" />
17+
<meta content="MinIO Console" name="description" />
1718
<!--
1819
manifest.json provides metadata used when your web app is installed on a
1920
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
2021
-->
2122
<link href="%PUBLIC_URL%/styles/root-styles.css" rel="stylesheet" />
2223
<link
24+
href="%PUBLIC_URL%/apple-icon-180x180.png"
2325
rel="apple-touch-icon"
2426
sizes="180x180"
25-
href="%PUBLIC_URL%/apple-icon-180x180.png"
2627
/>
2728
<link
29+
href="%PUBLIC_URL%/favicon-32x32.png"
2830
rel="icon"
29-
type="image/png"
3031
sizes="32x32"
31-
href="%PUBLIC_URL%/favicon-32x32.png"
32+
type="image/png"
3233
/>
3334
<link
35+
href="%PUBLIC_URL%/favicon-96x96.png"
3436
rel="icon"
35-
type="image/png"
3637
sizes="96x96"
37-
href="%PUBLIC_URL%/favicon-96x96.png"
38+
type="image/png"
3839
/>
3940
<link
41+
href="%PUBLIC_URL%/favicon-16x16.png"
4042
rel="icon"
41-
type="image/png"
4243
sizes="16x16"
43-
href="%PUBLIC_URL%/favicon-16x16.png"
44+
type="image/png"
4445
/>
45-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
46+
<link href="%PUBLIC_URL%/manifest.json" rel="manifest" />
4647
<link
47-
rel="mask-icon"
48-
href="%PUBLIC_URL%/safari-pinned-tab.svg"
4948
color="#3a4e54"
49+
href="%PUBLIC_URL%/safari-pinned-tab.svg"
50+
rel="mask-icon"
5051
/>
5152
<!--
5253
Notice the use of %PUBLIC_URL% in the tags above.
@@ -71,22 +72,22 @@
7172
"
7273
cx="44"
7374
cy="44"
74-
r="20.2"
7575
fill="none"
76+
r="20.2"
7677
stroke-width="3.6"
7778
></circle>
7879
</svg>
7980
</div>
8081
</div>
8182
<!--
82-
This HTML file is a template.
83-
If you open it directly in the browser, you will see an empty page.
83+
This HTML file is a template.
84+
If you open it directly in the browser, you will see an empty page.
8485
85-
You can add webfonts, meta tags, or analytics to this file.
86-
The build step will place the bundled scripts into the <body> tag.
86+
You can add webfonts, meta tags, or analytics to this file.
87+
The build step will place the bundled scripts into the <body> tag.
8788
88-
To begin the development, run `npm start` or `yarn start`.
89-
To create a production bundle, use `npm run build` or `yarn build`.
90-
-->
89+
To begin the development, run `npm start` or `yarn start`.
90+
To create a production bundle, use `npm run build` or `yarn build`.
91+
-->
9192
</body>
9293
</html>

portal-ui/src/ProtectedRoutes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import { connect } from "react-redux";
2020
import { AppState } from "./store";
2121
import {
2222
consoleOperatorMode,
23-
userLoggedIn,
2423
setDistributedMode,
24+
userLoggedIn,
2525
} from "./actions";
2626
import api from "./common/api";
2727
import { saveSessionResponse } from "./screens/Console/actions";

portal-ui/src/common/api/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
import request from "superagent";
1818
import get from "lodash/get";
1919
import { clearSession } from "../utils";
20-
import { baseUrl } from "../../history";
2120
import { ErrorResponseHandler } from "../types";
2221

2322
export class API {
2423
invoke(method: string, url: string, data?: object) {
25-
const targetURL = `${baseUrl}${url}`.replace(/\/\//g, "/");
24+
let targetURL = url;
25+
if (targetURL[0] === "/") {
26+
targetURL = targetURL.substr(1);
27+
}
2628
return request(method, targetURL)
2729
.send(data)
2830
.then((res) => res.body)

portal-ui/src/history.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,4 @@ import { BrowserHistoryBuildOptions } from "history/createBrowserHistory";
33

44
let browserHistoryOpts: BrowserHistoryBuildOptions = {};
55

6-
export let baseUrl = "";
7-
8-
if (`${window.location.pathname}`.startsWith("/api/proxy/")) {
9-
// grab from api to the tenant name (/api/proxy/namespace/tenant)
10-
const urlParts = `${window.location.pathname}`.split("/").slice(0, 5);
11-
browserHistoryOpts.basename = urlParts.join("/");
12-
baseUrl = `${urlParts.join("/")}/`;
13-
}
14-
156
export default createBrowserHistory(browserHistoryOpts);

portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjects.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import RewindEnable from "./RewindEnable";
6666

6767
import DeleteMultipleObjects from "./DeleteMultipleObjects";
6868
import PreviewFileModal from "../Preview/PreviewFileModal";
69-
import { baseUrl } from "../../../../../../history";
7069
import ScreenTitle from "../../../../Common/ScreenTitle/ScreenTitle";
7170
import AddFolderIcon from "../../../../../../icons/AddFolderIcon";
7271
import HistoryIcon from "../../../../../../icons/HistoryIcon";
@@ -597,7 +596,7 @@ const ListObjects = ({
597596
}
598597
e.preventDefault();
599598
let files = e.target.files;
600-
let uploadUrl = `${baseUrl}/api/v1/buckets/${bucketName}/objects/upload`;
599+
let uploadUrl = `api/v1/buckets/${bucketName}/objects/upload`;
601600
if (encodedPath !== "") {
602601
uploadUrl = `${uploadUrl}?prefix=${encodedPath}`;
603602
}

portal-ui/src/screens/Console/Common/PageHeader/PageHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const PageHeader = ({
6363
return (
6464
<Grid
6565
container
66-
className={classes.headerContainer}
66+
className={`${classes.headerContainer} page-header`}
6767
direction="row"
6868
alignItems="center"
6969
>

portal-ui/src/screens/Console/Console.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ const Dashboard = React.lazy(() => import("./Dashboard/Dashboard"));
9595
const Account = React.lazy(() => import("./Account/Account"));
9696
const Users = React.lazy(() => import("./Users/Users"));
9797
const Groups = React.lazy(() => import("./Groups/Groups"));
98-
const ConfigurationMain = React.lazy(
99-
() => import("./Configurations/ConfigurationMain")
100-
);
98+
10199
const TenantDetails = React.lazy(
102100
() => import("./Tenants/TenantDetails/TenantDetails")
103101
);

portal-ui/src/screens/Console/Menu/Menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ const Menu = ({
461461
component: NavLink,
462462
to: "/license",
463463
name: "License",
464-
icon: <LicenseIcon />,
464+
icon: LicenseIcon,
465465
},
466466
{
467467
...documentation,

portal-ui/src/screens/Console/Tenants/TenantDetails/hop/Hop.tsx

Lines changed: 75 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Theme } from "@mui/material/styles";
1919
import createStyles from "@mui/styles/createStyles";
2020
import withStyles from "@mui/styles/withStyles";
2121
import { Link } from "react-router-dom";
22-
import { CircularProgress, IconButton } from "@mui/material";
22+
import { Box, CircularProgress, IconButton } from "@mui/material";
2323
import PageHeader from "../../../Common/PageHeader/PageHeader";
2424
import { containerForHeader } from "../../../Common/FormComponents/common/styleLibrary";
2525
import ExitToAppIcon from "@mui/icons-material/ExitToApp";
@@ -46,15 +46,20 @@ const styles = (theme: Theme) =>
4646
divContainer: {
4747
position: "absolute",
4848
left: 0,
49-
top: 77,
50-
height: "calc(100vh - 77px)",
49+
top: 80,
50+
height: "calc(100vh - 81px)",
5151
width: "100%",
5252
},
5353
loader: {
5454
width: 100,
5555
margin: "auto",
5656
marginTop: 80,
5757
},
58+
59+
pageHeader: {
60+
borderBottom: "1px solid #dedede",
61+
},
62+
5863
...containerForHeader(theme.spacing(4)),
5964
});
6065

@@ -66,72 +71,76 @@ const Hop = ({ classes, match }: IHopSimple) => {
6671
const consoleFrame = React.useRef<HTMLIFrameElement>(null);
6772

6873
return (
69-
<React.Fragment>
70-
<PageHeader
71-
label={
72-
<Fragment>
73-
<Link to={"/tenants"} className={classes.breadcrumLink}>
74-
Tenants
75-
</Link>
76-
{` > `}
77-
<Link
78-
to={`/namespaces/${tenantNamespace}/tenants/${tenantName}`}
79-
className={classes.breadcrumLink}
80-
>
81-
{match.params["tenantName"]}
82-
</Link>
83-
{` > Management`}
84-
</Fragment>
85-
}
86-
actions={
87-
<React.Fragment>
88-
<IconButton
89-
color="primary"
90-
aria-label="Refresh List"
91-
component="span"
92-
onClick={() => {
93-
if (
94-
consoleFrame !== null &&
95-
consoleFrame.current !== null &&
96-
consoleFrame.current.contentDocument !== null
97-
) {
98-
const loc =
99-
consoleFrame.current.contentDocument.location.toString();
74+
<Fragment>
75+
<Box className={classes.pageHeader}>
76+
<PageHeader
77+
label={
78+
<Fragment>
79+
<Link to={"/tenants"} className={classes.breadcrumLink}>
80+
Tenants
81+
</Link>
82+
{` > `}
83+
<Link
84+
to={`/namespaces/${tenantNamespace}/tenants/${tenantName}`}
85+
className={classes.breadcrumLink}
86+
>
87+
{match.params["tenantName"]}
88+
</Link>
89+
{` > Management`}
90+
</Fragment>
91+
}
92+
actions={
93+
<React.Fragment>
94+
<IconButton
95+
color="primary"
96+
aria-label="Refresh List"
97+
component="span"
98+
onClick={() => {
99+
if (
100+
consoleFrame !== null &&
101+
consoleFrame.current !== null &&
102+
consoleFrame.current.contentDocument !== null
103+
) {
104+
const loc =
105+
consoleFrame.current.contentDocument.location.toString();
100106

101-
let add = "&";
107+
let add = "&";
102108

103-
if (loc.indexOf("?") < 0) {
104-
add = `?`;
105-
}
109+
if (loc.indexOf("?") < 0) {
110+
add = `?`;
111+
}
106112

107-
if (loc.indexOf("cp=y") < 0) {
108-
const next = `${loc}${add}cp=y`;
109-
consoleFrame.current.contentDocument.location.replace(next);
110-
} else {
111-
consoleFrame.current.contentDocument.location.reload();
113+
if (loc.indexOf("cp=y") < 0) {
114+
const next = `${loc}${add}cp=y`;
115+
consoleFrame.current.contentDocument.location.replace(
116+
next
117+
);
118+
} else {
119+
consoleFrame.current.contentDocument.location.reload();
120+
}
112121
}
113-
}
114-
}}
115-
size="large"
116-
>
117-
<RefreshIcon />
118-
</IconButton>
119-
<IconButton
120-
color="primary"
121-
aria-label="Refresh List"
122-
component="span"
123-
onClick={() => {
124-
history.push(
125-
`/namespaces/${tenantNamespace}/tenants/${tenantName}`
126-
);
127-
}}
128-
size="large"
129-
>
130-
<ExitToAppIcon />
131-
</IconButton>
132-
</React.Fragment>
133-
}
134-
/>
122+
}}
123+
size="large"
124+
>
125+
<RefreshIcon />
126+
</IconButton>
127+
<IconButton
128+
color="primary"
129+
aria-label="Refresh List"
130+
component="span"
131+
onClick={() => {
132+
history.push(
133+
`/namespaces/${tenantNamespace}/tenants/${tenantName}`
134+
);
135+
}}
136+
size="large"
137+
>
138+
<ExitToAppIcon />
139+
</IconButton>
140+
</React.Fragment>
141+
}
142+
/>
143+
</Box>
135144
<div className={classes.divContainer}>
136145
{loading && (
137146
<div className={classes.loader}>
@@ -148,7 +157,7 @@ const Hop = ({ classes, match }: IHopSimple) => {
148157
}}
149158
/>
150159
</div>
151-
</React.Fragment>
160+
</Fragment>
152161
);
153162
};
154163

0 commit comments

Comments
 (0)