restore context path support

This commit is contained in:
Sebastian Sdorra
2018-08-27 15:47:02 +02:00
parent b09c46abcf
commit e6e1c5871a
19 changed files with 132 additions and 36 deletions

View File

@@ -1,7 +1,5 @@
// @flow
// get api base url from environment
const apiUrl = process.env.API_URL || process.env.PUBLIC_URL || "";
import { contextPath } from "./urls";
export const NOT_FOUND_ERROR = Error("not found");
export const UNAUTHORIZED_ERROR = Error("unauthorized");
@@ -34,7 +32,7 @@ export function createUrl(url: string) {
if (url.indexOf("/") !== 0) {
urlWithStartingSlash = "/" + urlWithStartingSlash;
}
return `${apiUrl}/api/rest/v2${urlWithStartingSlash}`;
return `${contextPath}/api/rest/v2${urlWithStartingSlash}`;
}
class ApiClient {

View File

@@ -0,0 +1,18 @@
//@flow
import React from "react";
import { withContextPath } from "../urls";
type Props = {
src: string,
alt: string,
className: any
};
class Image extends React.Component<Props> {
render() {
const { src, alt, className } = this.props;
return <img className={className} src={withContextPath(src)} alt={alt} />;
}
}
export default Image;

View File

@@ -2,6 +2,7 @@
import React from "react";
import { translate } from "react-i18next";
import injectSheet from "react-jss";
import Image from "./Image";
const styles = {
wrapper: {
@@ -35,7 +36,7 @@ class Loading extends React.Component<Props> {
return (
<div className={classes.wrapper}>
<div className={classes.loading}>
<img
<Image
className={classes.image}
src="/images/loading.svg"
alt={t("loading.alt")}

View File

@@ -1,6 +1,7 @@
//@flow
import React from "react";
import { translate } from "react-i18next";
import Image from "./Image";
type Props = {
t: string => string
@@ -9,7 +10,7 @@ type Props = {
class Logo extends React.Component<Props> {
render() {
const { t } = this.props;
return <img src="images/logo.png" alt={t("logo.alt")} />;
return <Image src="/images/logo.png" alt={t("logo.alt")} />;
}
}

View File

@@ -62,11 +62,7 @@ class PluginLoader extends React.Component<Props, State> {
const promises = [];
for (let bundle of plugin.bundles) {
// skip old bundles
// TODO remove old bundles
if (bundle.indexOf("/") !== 0) {
promises.push(this.loadBundle(bundle));
}
promises.push(this.loadBundle(bundle));
}
return Promise.all(promises);
};

View File

@@ -16,6 +16,7 @@ import { SubmitButton } from "../components/buttons";
import classNames from "classnames";
import ErrorNotification from "../components/ErrorNotification";
import Image from "../components/Image";
const styles = {
avatar: {
@@ -105,7 +106,7 @@ class Login extends React.Component<Props, State> {
<p className="subtitle">{t("login.subtitle")}</p>
<div className={classNames("box", classes.avatarSpacing)}>
<figure className={classes.avatar}>
<img
<Image
className={classes.avatarImage}
src="/images/blib.jpg"
alt={t("login.logo-alt")}

View File

@@ -2,9 +2,9 @@ import i18n from "i18next";
import Backend from "i18next-fetch-backend";
import LanguageDetector from "i18next-browser-languagedetector";
import { reactI18nextModule } from "react-i18next";
import { withContextPath } from "./urls";
const loadPath =
(process.env.PUBLIC_URL || "") + "/locales/{{lng}}/{{ns}}.json";
const loadPath = withContextPath("/locales/{{lng}}/{{ns}}.json");
// TODO load locales for moment

View File

@@ -16,11 +16,11 @@ import createReduxStore from "./createReduxStore";
import { ConnectedRouter } from "react-router-redux";
import PluginLoader from "./components/PluginLoader";
const publicUrl: string = process.env.PUBLIC_URL || "";
import { contextPath } from "./urls";
// Create a history of your choosing (we're using a browser history in this case)
const history: BrowserHistory = createHistory({
basename: publicUrl
basename: contextPath
});
// Add the reducer to your store on the `router` key

View File

@@ -2,6 +2,7 @@
import React from "react";
import { ExtensionPoint } from "@scm-manager/ui-extensions";
import type { Repository } from "../../types/Repositories";
import Image from "../../../components/Image";
type Props = {
repository: Repository
@@ -13,7 +14,7 @@ class RepositoryAvatar extends React.Component<Props> {
return (
<p className="image is-64x64">
<ExtensionPoint name="repos.repository-avatar" props={{ repository }}>
<img src="/images/blib.jpg" alt="Logo" />
<Image src="/images/blib.jpg" alt="Logo" />
</ExtensionPoint>
</p>
);

6
scm-ui/src/urls.js Normal file
View File

@@ -0,0 +1,6 @@
// @flow
export const contextPath = window.ctxPath || "";
export function withContextPath(path: string) {
return contextPath + path;
}