Move spaceapi proxy prefix from config to spaceapi urls

This commit is contained in:
s3lph 2023-01-06 02:50:38 +01:00
parent 22c97c3155
commit 474fc0ef53
Signed by: s3lph
GPG key ID: 8AC98A811E5BEFF5
3 changed files with 8 additions and 12 deletions

View file

@ -10,7 +10,6 @@ jinja_environment:
baseurl_abs: https://chaostreff.ch/ baseurl_abs: https://chaostreff.ch/
baseurl: / baseurl: /
spaceapi_proxy_endpoint: /spaceapi-proxy
htaccess_spaceapi_proxy: yes htaccess_spaceapi_proxy: yes
hackerspaces: hackerspaces:
@ -28,7 +27,7 @@ jinja_environment:
contact: contact:
ml: 'https://lists.chaostreff.ch/postorius/lists/basel.chaostreff.ch/' ml: 'https://lists.chaostreff.ch/postorius/lists/basel.chaostreff.ch/'
matrix: 'https://mto.kabelsalat.ch/#/#basel:kabelsalat.ch' matrix: 'https://mto.kabelsalat.ch/#/#basel:kabelsalat.ch'
spaceapi: '/https/spaceapi.kabelsalat.ch/' spaceapi: '/spaceapi-proxy/https/spaceapi.kabelsalat.ch/'
- name: 'CCC Zürich' - name: 'CCC Zürich'
address: 'Neue Hard 12, 8005 Zürich' address: 'Neue Hard 12, 8005 Zürich'
@ -43,7 +42,7 @@ jinja_environment:
contact: contact:
ml: 'https://lists.chaostreff.ch/postorius/lists/zuerich.chaostreff.ch/' ml: 'https://lists.chaostreff.ch/postorius/lists/zuerich.chaostreff.ch/'
ml: 'https://lists.chaostreff.ch/postorius/lists/bitwaescherei.chaostreff.ch/' ml: 'https://lists.chaostreff.ch/postorius/lists/bitwaescherei.chaostreff.ch/'
spaceapi: '/https/www.ccczh.ch/api/v13/' spaceapi: '/spaceapi-proxy/https/www.ccczh.ch/api/v13/'
- name: 'Chaostreff Bern' - name: 'Chaostreff Bern'
address: 'Kyburgstrasse 13, 3013 Bern' address: 'Kyburgstrasse 13, 3013 Bern'
@ -58,7 +57,7 @@ jinja_environment:
contact: contact:
ml: 'https://lists.chaostreff.ch/postorius/lists/bern.chaostreff.ch/' ml: 'https://lists.chaostreff.ch/postorius/lists/bern.chaostreff.ch/'
email: 'info(ät)chaostreffbern(punkt)ch' email: 'info(ät)chaostreffbern(punkt)ch'
spaceapi: '/https/www.chaosbern.ch/spaceapi.json' spaceapi: '/spaceapi-proxy/https/www.chaosbern.ch/spaceapi.json'
- name: 'Coredump' - name: 'Coredump'
address: 'Eichwiesstrasse 4, 8645 Jona' address: 'Eichwiesstrasse 4, 8645 Jona'
@ -71,7 +70,7 @@ jinja_environment:
en: 'Every Monday from 20:00' en: 'Every Monday from 20:00'
web: 'https://coredump.ch/' web: 'https://coredump.ch/'
contact: {} contact: {}
spaceapi: '/https/status.crdmp.ch/' spaceapi: '/spaceapi-proxy/https/status.crdmp.ch/'
- name: 'Eastermundingen' - name: 'Eastermundingen'
address: 'Steinbruchweg 16, 3072 Ostermundigen' address: 'Steinbruchweg 16, 3072 Ostermundigen'

View file

@ -5,7 +5,6 @@ window.onload = (ev) => {
{ name: '{{ space.name }}', address: '{{ space.address }}', lat: {{ space.lat }}, lon: {{ space.lon }}, open: '{{ space.open[lang] }}', web: '{{ space.contact.web }}', spaceapi: {% if 'spaceapi' in space %}'{{ space.spaceapi }}'{% else %}null{% endif %} }, { name: '{{ space.name }}', address: '{{ space.address }}', lat: {{ space.lat }}, lon: {{ space.lon }}, open: '{{ space.open[lang] }}', web: '{{ space.contact.web }}', spaceapi: {% if 'spaceapi' in space %}'{{ space.spaceapi }}'{% else %}null{% endif %} },
{% endfor %} {% endfor %}
]; ];
let SPACEAPI_PROXY = '{{ spaceapi_proxy_endpoint }}';
let blueIcon = new L.Icon({ let blueIcon = new L.Icon({
iconUrl: '{{ baseurl }}static/img/leaflet-marker-blue.png', iconUrl: '{{ baseurl }}static/img/leaflet-marker-blue.png',
@ -29,8 +28,8 @@ window.onload = (ev) => {
let marker = L.marker([spaces[i].lat, spaces[i].lon], {icon: blueIcon}) let marker = L.marker([spaces[i].lat, spaces[i].lon], {icon: blueIcon})
.bindPopup(`<b>${spaces[i].name}</b><address>${spaces[i].address.replaceAll(',', '<br/>')}</address><a href="${spaces[i].web}">${spaces[i].web}</a>`) .bindPopup(`<b>${spaces[i].name}</b><address>${spaces[i].address.replaceAll(',', '<br/>')}</address><a href="${spaces[i].web}">${spaces[i].web}</a>`)
.addTo(map); .addTo(map);
if (spaces[i].spaceapi !== undefined) { if (spaces[i].spaceapi !== null) {
fetch(SPACEAPI_PROXY + spaces[i].spaceapi, { fetch(spaces[i].spaceapi, {
headers: { 'Accept': 'application/json' }, headers: { 'Accept': 'application/json' },
}).then(resp => resp.json()).then(json => { }).then(resp => resp.json()).then(json => {
if (json.state == undefined || json.state.open == undefined) { if (json.state == undefined || json.state.open == undefined) {

View file

@ -1,15 +1,13 @@
# Language-specific index based on Accept-Language header # Language-specific index based on Accept-Language header
DirectoryIndex index.var index.html DirectoryIndex index.var index.html
# Optional: Redirect to language specific subsite, rather than showing
# language specific content at the root
{% if htaccess_spaceapi_proxy %} {% if htaccess_spaceapi_proxy %}
# SpaceAPI proxy service workaround for missing CORS headers # SpaceAPI proxy service workaround for missing CORS headers
RewriteEngine on RewriteEngine on
{%- for space in hackerspaces %} {%- for space in hackerspaces %}
{%- if 'spaceapi' in space %} {%- if 'spaceapi' in space and space.spaceapi.startswith('/') %}
RewriteRule ^spaceapi-proxy{{ space.spaceapi }}$ {{ space.spaceapi.split('/', 2)[1] }}://{{ space.spaceapi.split('/', 2)[2] }} [P,L] RewriteRule ^{{ space.spaceapi[1:] }}$ {{ space.spaceapi.split('/', 3)[2] }}://{{ space.spaceapi.split('/', 3)[3] }} [P,L]
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
{%- endif %} {%- endif %}