Skip to content

Commit

Permalink
keep #211 fix but still fixes bad missing /api/ urls
Browse files Browse the repository at this point in the history
  • Loading branch information
boogheta committed Sep 4, 2023
1 parent 09579e4 commit c55da0c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/actions/corpora.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const fetchCorpora = (serverUrl) => (dispatch) => {
return dispatch(receiveCorpora(serverUrl, res))
})
.catch((error) => {
console.log("ERROR", res);
console.log("ERROR", error);
return dispatch({
type: FETCH_CORPORA_FAILURE,
payload: { error, serverUrl }
Expand Down
26 changes: 3 additions & 23 deletions app/containers/Login/ServerForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,8 @@ const ServerForm = ({
fetchCorpora(server.url)
saveAndRedirect()
}, () => {
// Try alternative url ending with /api/ if missing and fix it automatically if working
const altUrl = server.url.replace(/(\/|api)*$/, '/api/')
console.log("API server url", server.url, "seems unaccessible, trying to rewrite it:", altUrl)
if (! /\/api\/$/.test(server.url)) {
fetchServerStatus(altUrl)
.then(() => {
if (fullConfig && typeof fullConfig === 'object') {
fullConfig.url = altUrl
}
data.url = altUrl
setSubmitting(true)
setErrors([])
fetchCorpora(altUrl)
saveAndRedirect()
}, () => {
setSubmitting(false)
setErrors(['error.server-url'])
})
} else {
setSubmitting(false)
setErrors(['error.server-url'])
}
setSubmitting(false)
setErrors(['error.server-url'])
})
}

Expand All @@ -172,7 +152,7 @@ const ServerForm = ({
fullConfig :
{ ...data }

server.url = server.url.replace(/#.*$/, '')
server.url = server.url.replace(/#.*$/, '').replace(/(\/|api)*$/, '/api/')

if (!server.password) delete server.password
server.home = server.url.replace(/[/-]+api\/+?$/, '/')
Expand Down

0 comments on commit c55da0c

Please sign in to comment.