Skip to content

Commit

Permalink
Simpler CORS needs for the WordPress Tribe Events Calendar.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabacab committed Oct 6, 2023
1 parent c44a3f5 commit 16cfba8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions static/js/event-source-data/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ const EventSourceData = [
id: 'gomag',
className: 'gomag',
url: 'http://gomag.com/wp-json/tribe/events/v1/events?per_page=50&geoloc=true&geoloc_lat=40.7127837&geoloc_lng=-74.00594130000002',
useCorsProxy: true,
color: '#ed008c'
},
{
Expand Down
14 changes: 8 additions & 6 deletions static/js/event-sources/wordpress-tribe-events-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import FullCalendarEvent from '../event.js';

export default function WordPressTribeEvents (optionsObj) {
this.events = [];
this.url = new URL(optionsObj.url);
this.useCorsProxy = optionsObj.useCorsProxy;

var url = new URL(optionsObj.url);
// Set up initial HTTP query.
var url = this.url;
var url_start_date = optionsObj.fetchInfo.start.toISOString().replace(/T.*/, ' 00:00:00');
var url_end_date = optionsObj.fetchInfo.end.toISOString().replace(/T.*/, ' 00:00:00');
url.searchParams.set('start_date', url_start_date);
Expand All @@ -31,17 +34,16 @@ WordPressTribeEvents.prototype.fetchAll = async function (url) {
await this.fetch(url);
this.parse();
while (this.json.next_rest_url) {
let u = (url.host === new URL(corsbase).host)
? corsbase + '/' + this.json.next_rest_url
: this.json.next_rest_url;
await this.fetch(u);
await this.fetch(new URL(this.json.next_rest_url));
this.parse();
}
return this;
};

WordPressTribeEvents.prototype.fetch = async function (url) {
this.url = corsbase + '/' + url;
var url = (this.useCorsProxy)
? new URL(`${corsbase}/${url.toString()}`)
: url;
var response = await fetch(url);
var json = {};
try {
Expand Down

0 comments on commit 16cfba8

Please sign in to comment.