Browse Source

refactored getDisplayURL

dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 7 years ago
parent
commit
2360ce36ac
  1. 1
      internal/handlers/handlers.go
  2. 5
      web/src/Home/Home.js
  3. 5
      web/src/Lookup/Lookup.js
  4. 5
      web/src/Recent/Recent.js
  5. 5
      web/src/util/util.js

1
internal/handlers/handlers.go

@ -163,7 +163,6 @@ func (h *Handler) setHandlers() error {
h.engine.GET("/api/v1/info", h.handleInfo)
h.engine.GET("/d/:id/:hash", h.handleDelete)
h.engine.GET("/ok", h.handleHealthcheck)
h.engine.GET("/displayurl", h.handleDisplayURL)
// Handling the shorted URLs, if no one exists, it checks
// in the filesystem and sets headers for caching

5
web/src/Home/Home.js

@ -36,9 +36,8 @@ export default class HomeComponent extends Component {
componentDidMount() {
this.urlInput.focus()
fetch("/displayurl")
.then(response => response.json())
.then(data => this.setState({displayURL: data}));
util.getDisplayURL()
.then(displayURL => this.setState({ displayURL }));
}
handleURLSubmit = () => {
if (!this.state.showCustomIDError) {

5
web/src/Lookup/Lookup.js

@ -10,9 +10,8 @@ export default class LookupComponent extends Component {
displayURL: window.location.origin
}
componentDidMount() {
fetch("/displayurl")
.then(response => response.json())
.then(data => this.setState({displayURL: data}));
util.getDisplayURL()
.then(displayURL => this.setState({ displayURL }));
}
handleURLChange = (e, { value }) => this.url = value
handleURLSubmit = () => {

5
web/src/Recent/Recent.js

@ -14,9 +14,8 @@ export default class RecentComponent extends Component {
componentDidMount() {
this.loadRecentURLs()
fetch("/displayurl")
.then(response => response.json())
.then(data => this.setState({displayURL: data}));
util.getDisplayURL()
.then(displayURL => this.setState({ displayURL }));
}
loadRecentURLs = () => {

5
web/src/util/util.js

@ -56,4 +56,9 @@ export default class UtilHelper {
.then(res => cbSucc ? cbSucc(res) : null)
.catch(e => this._reportError(e, "recent"))
}
static getDisplayURL() {
return fetch("/api/v1/displayURL")
.then(res => res.ok ? res.json() : Promise.reject(res.json()))
.catch(e => this._reportError(e, "getDisplayURL"))
}
}

Loading…
Cancel
Save