Use location.origin as default base URL
This commit is contained in:
parent
c5ce51f242
commit
420e35c33c
7 changed files with 16 additions and 19 deletions
|
@ -10,14 +10,13 @@ import DialogTitle from '@mui/material/DialogTitle';
|
|||
import {Autocomplete, Checkbox, FormControlLabel, useMediaQuery} from "@mui/material";
|
||||
import theme from "./theme";
|
||||
import api from "../app/Api";
|
||||
import config from "../app/config";
|
||||
import {topicUrl, validTopic, validUrl} from "../app/utils";
|
||||
import Box from "@mui/material/Box";
|
||||
import userManager from "../app/UserManager";
|
||||
import subscriptionManager from "../app/SubscriptionManager";
|
||||
import poller from "../app/Poller";
|
||||
|
||||
const publicBaseUrl = "https://ntfy.sh"
|
||||
const publicBaseUrl = "https://ntfy.sh";
|
||||
|
||||
const SubscribeDialog = (props) => {
|
||||
const [baseUrl, setBaseUrl] = useState("");
|
||||
|
@ -25,7 +24,7 @@ const SubscribeDialog = (props) => {
|
|||
const [showLoginPage, setShowLoginPage] = useState(false);
|
||||
const fullScreen = useMediaQuery(theme.breakpoints.down('sm'));
|
||||
const handleSuccess = async () => {
|
||||
const actualBaseUrl = (baseUrl) ? baseUrl : config.defaultBaseUrl;
|
||||
const actualBaseUrl = (baseUrl) ? baseUrl : window.location.origin;
|
||||
const subscription = {
|
||||
id: topicUrl(actualBaseUrl, topic),
|
||||
baseUrl: actualBaseUrl,
|
||||
|
@ -61,11 +60,11 @@ const SubscribeDialog = (props) => {
|
|||
const SubscribePage = (props) => {
|
||||
const [anotherServerVisible, setAnotherServerVisible] = useState(false);
|
||||
const [errorText, setErrorText] = useState("");
|
||||
const baseUrl = (anotherServerVisible) ? props.baseUrl : config.defaultBaseUrl;
|
||||
const baseUrl = (anotherServerVisible) ? props.baseUrl : window.location.origin;
|
||||
const topic = props.topic;
|
||||
const existingTopicUrls = props.subscriptions.map(s => topicUrl(s.baseUrl, s.topic));
|
||||
const existingBaseUrls = Array.from(new Set([publicBaseUrl, ...props.subscriptions.map(s => s.baseUrl)]))
|
||||
.filter(s => s !== config.defaultBaseUrl);
|
||||
.filter(s => s !== window.location.origin);
|
||||
const handleSubscribe = async () => {
|
||||
const user = await userManager.get(baseUrl); // May be undefined
|
||||
const username = (user) ? user.username : "anonymous";
|
||||
|
@ -92,7 +91,7 @@ const SubscribePage = (props) => {
|
|||
const isExistingTopicUrl = existingTopicUrls.includes(topicUrl(baseUrl, topic));
|
||||
return validTopic(topic) && validUrl(baseUrl) && !isExistingTopicUrl;
|
||||
} else {
|
||||
const isExistingTopicUrl = existingTopicUrls.includes(topicUrl(config.defaultBaseUrl, topic)); // FIXME
|
||||
const isExistingTopicUrl = existingTopicUrls.includes(topicUrl(window.location.origin, topic)); // FIXME
|
||||
return validTopic(topic) && !isExistingTopicUrl;
|
||||
}
|
||||
})();
|
||||
|
@ -127,7 +126,7 @@ const SubscribePage = (props) => {
|
|||
inputValue={props.baseUrl}
|
||||
onInputChange={(ev, newVal) => props.setBaseUrl(newVal)}
|
||||
renderInput={ (params) =>
|
||||
<TextField {...params} placeholder={config.defaultBaseUrl} variant="standard"/>
|
||||
<TextField {...params} placeholder={window.location.origin} variant="standard"/>
|
||||
}
|
||||
/>}
|
||||
</DialogContent>
|
||||
|
@ -143,7 +142,7 @@ const LoginPage = (props) => {
|
|||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [errorText, setErrorText] = useState("");
|
||||
const baseUrl = (props.baseUrl) ? props.baseUrl : config.defaultBaseUrl;
|
||||
const baseUrl = (props.baseUrl) ? props.baseUrl : window.location.origin;
|
||||
const topic = props.topic;
|
||||
const handleLogin = async () => {
|
||||
const user = {baseUrl, username, password};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue