Skip to content

Commit

Permalink
Merge pull request #5 from netgen-layouts/LAYOUTS-674-bypass-varnish
Browse files Browse the repository at this point in the history
LAYOUTS-674 adjust api url before sending request so we bypass varnish
  • Loading branch information
emodric authored Mar 24, 2023
2 parents c980328 + 587d064 commit 4b8d4ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions components/block-picker/element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {LitElement, html} from 'lit';
import {classMap} from 'lit/directives/class-map.js';
import { addTimestampToUrl } from '../component-helper.js';
import { CloseIcon } from '../icons.js';
import style from './style.js';

Expand Down Expand Up @@ -162,10 +163,9 @@ export default class BlockPicker extends LitElement {
}
}


async handleRefreshView(blockId) {

return await fetch(window.location.href)
const apiUrl = addTimestampToUrl(window.location.href)
return await fetch(apiUrl)
.then(resp => {
return resp.text()
})
Expand Down
13 changes: 5 additions & 8 deletions components/block/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {classMap} from 'lit/directives/class-map.js';
import style from './style.js';

import { ArrowDownIcon, ArrowUpIcon, BreadcrumbArrowIcon, PlusIcon, RefreshIcon } from '../icons.js';
import { addTimestampToUrl } from '../component-helper.js';

export default class Block extends LitElement {
static styles = [style];
Expand Down Expand Up @@ -115,12 +116,11 @@ export default class Block extends LitElement {
return this.slottedChildren[0]?.querySelectorAll('ngl-block')
}
// GETTERS - end


async fetch() {
this.loading = true;
try {
const resp = await fetch(window.location.href);
const apiUrl = addTimestampToUrl(window.location.href)
const resp = await fetch(apiUrl);
return resp.text();
} finally {
this.loading = false;
Expand Down Expand Up @@ -243,8 +243,6 @@ export default class Block extends LitElement {
select() {
if (this.isInLinkedZone) return;

console.debug(this.model)

this.model.trigger('edit');
this.isSelected = true;
}
Expand Down Expand Up @@ -339,12 +337,11 @@ export default class Block extends LitElement {
this.handleRefreshView()
})
}

}

async handleRefreshView() {

return await fetch(window.location.href)
const apiUrl = addTimestampToUrl(window.location.href)
return await fetch(apiUrl)
.then(resp => {
return resp.text()
})
Expand Down
7 changes: 7 additions & 0 deletions components/component-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const addTimestampToUrl = (url) => {
const urlObject = new URL(url)
let searchParams = new URLSearchParams(urlObject.search)
searchParams.set('t', Date.now())

return `${urlObject.origin + urlObject.pathname}?${searchParams.toString()}`
}

0 comments on commit 4b8d4ae

Please sign in to comment.