mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
Fix web root path confusion
Remove basename in favor of making webRoot absolute. The distinction between the two were supposed to be that basename was absolute and did not have a trailing slash while webRoot was relative and had a traling slash. This was not how it ended up working in the code, which lead to double forward slashes in requests sent out when webRoot was not equal to './'.
This commit is contained in:
1 parent
ceae2b25b5
commit
bd53339532
7 files changed
+6
-17
No files matched your search
@@ -5,7 +5,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>Clusterio</title>
|
<title>Clusterio</title>
|
||||||
<script>
|
<script>
|
||||||
window.webRoot = "__WEB_ROOT__";
|
window.webRoot = new URL("__WEB_ROOT__", document.location).pathname;
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
// Calculate basedir of application based on current location and
|
|
||||||
// the provided web_root from master server.
|
|
||||||
const location = new URL(window.webRoot, document.location);
|
|
||||||
const basename = location.pathname !== "/" ? location.pathname : "";
|
|
||||||
|
|
||||||
export default basename;
|
|
||||||
@@ -7,7 +7,6 @@ import libConfig from "@clusterio/lib/config";
|
|||||||
import libPlugin from "@clusterio/lib/plugin";
|
import libPlugin from "@clusterio/lib/plugin";
|
||||||
import { ConsoleTransport, WebConsoleFormat, logger } from "@clusterio/lib/logging";
|
import { ConsoleTransport, WebConsoleFormat, logger } from "@clusterio/lib/logging";
|
||||||
|
|
||||||
import basename from "./basename";
|
|
||||||
import App from "./components/App";
|
import App from "./components/App";
|
||||||
import { Control, ControlConnector } from "./util/websocket";
|
import { Control, ControlConnector } from "./util/websocket";
|
||||||
|
|
||||||
@@ -28,7 +27,7 @@ async function loadScript(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadPlugins() {
|
async function loadPlugins() {
|
||||||
let response = await fetch(`${basename}/api/plugins`);
|
let response = await fetch(`${webRoot}api/plugins`);
|
||||||
let pluginList;
|
let pluginList;
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
pluginList = await response.json();
|
pluginList = await response.json();
|
||||||
@@ -42,7 +41,7 @@ async function loadPlugins() {
|
|||||||
await __webpack_init_sharing__("default");
|
await __webpack_init_sharing__("default");
|
||||||
for (let meta of pluginList) {
|
for (let meta of pluginList) {
|
||||||
try {
|
try {
|
||||||
await loadScript(`${basename}/plugins/${meta.name}/remoteEntry.js`);
|
await loadScript(`${webRoot}plugins/${meta.name}/remoteEntry.js`);
|
||||||
let container = window[`plugin_${meta.name}`];
|
let container = window[`plugin_${meta.name}`];
|
||||||
if (!container) {
|
if (!container) {
|
||||||
throw new Error(`Plugin did not expose its container via plugin_${meta.name}`);
|
throw new Error(`Plugin did not expose its container via plugin_${meta.name}`);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { BrowserRouter } from "react-router-dom";
|
|||||||
|
|
||||||
import { logger } from "@clusterio/lib/logging";
|
import { logger } from "@clusterio/lib/logging";
|
||||||
|
|
||||||
import basename from "../basename";
|
|
||||||
import ErrorBoundary from "./ErrorBoundary";
|
import ErrorBoundary from "./ErrorBoundary";
|
||||||
import SiteLayout from "./SiteLayout";
|
import SiteLayout from "./SiteLayout";
|
||||||
import ControlContext from "./ControlContext";
|
import ControlContext from "./ControlContext";
|
||||||
@@ -89,7 +88,7 @@ export default function App(props) {
|
|||||||
<ErrorBoundary Component={ErrorCard}>
|
<ErrorBoundary Component={ErrorCard}>
|
||||||
<ControlContext.Provider value={props.control}>
|
<ControlContext.Provider value={props.control}>
|
||||||
<PluginsContext.Provider value={props.plugins}>
|
<PluginsContext.Provider value={props.plugins}>
|
||||||
<BrowserRouter basename={basename}>
|
<BrowserRouter basename={webRoot}>
|
||||||
{page}
|
{page}
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</PluginsContext.Provider>
|
</PluginsContext.Provider>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import React, { useEffect, useContext, useState } from "react";
|
|||||||
import { useHistory, useParams } from "react-router-dom";
|
import { useHistory, useParams } from "react-router-dom";
|
||||||
import { Alert, Descriptions, Spin } from "antd";
|
import { Alert, Descriptions, Spin } from "antd";
|
||||||
|
|
||||||
import basename from "../basename";
|
|
||||||
import PluginsContext from "./PluginsContext";
|
import PluginsContext from "./PluginsContext";
|
||||||
import PageLayout from "./PageLayout";
|
import PageLayout from "./PageLayout";
|
||||||
import { notifyErrorHandler } from "../util/notify";
|
import { notifyErrorHandler } from "../util/notify";
|
||||||
@@ -16,7 +15,7 @@ export default function PluginViewPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
let response = await fetch(`${basename}/api/plugins`);
|
let response = await fetch(`${webRoot}api/plugins`);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
setPluginList(await response.json());
|
setPluginList(await response.json());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { useHistory } from "react-router-dom";
|
|||||||
import { Table } from "antd";
|
import { Table } from "antd";
|
||||||
|
|
||||||
import notify from "../util/notify";
|
import notify from "../util/notify";
|
||||||
import basename from "../basename";
|
|
||||||
import PluginsContext from "./PluginsContext";
|
import PluginsContext from "./PluginsContext";
|
||||||
import PageLayout from "./PageLayout";
|
import PageLayout from "./PageLayout";
|
||||||
|
|
||||||
@@ -15,7 +14,7 @@ export default function PluginsPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
let response = await fetch(`${basename}/api/plugins`);
|
let response = await fetch(`${webRoot}api/plugins`);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
setPluginList(await response.json());
|
setPluginList(await response.json());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
export { default as basename } from "./basename.jsx";
|
|
||||||
export { default as bootstrap } from "./bootstrap.jsx";
|
export { default as bootstrap } from "./bootstrap.jsx";
|
||||||
export { default as notify, notifyErrorHandler } from "./util/notify.jsx";
|
export { default as notify, notifyErrorHandler } from "./util/notify.jsx";
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user