-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from technologiestiftung/feat/swimapi
feat: Swim api
- Loading branch information
Showing
11 changed files
with
41,317 additions
and
12,150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
MAPBOXKEY=YOUR_MAPBOX_KEY | ||
URL=http://localhost:5000 | ||
URL=http://localhost:5000 | ||
# the variables below need to be defined | ||
# in netlify's environment variables | ||
# to make the netlify/functions/swimapi.mts work | ||
# npx netlify-cli env:set SWIM_API_URL "https://your-swim-api-url" | ||
# Talk to KWB about the credentials | ||
SWIM_API_USER=abc | ||
SWIM_API_PASSWORD=def | ||
SWIM_API_URL=http://your-swim-api-url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ TODO.md | |
/public/build/ | ||
.DS_Store | ||
.coverage | ||
.env | ||
.env | ||
# Local Netlify folder | ||
.netlify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
const fetchMock = require('fetch-mock'); | ||
fetchMock.config.sendAsJson = false; | ||
const fetchMock = require('fetch-mock') | ||
fetchMock.config.sendAsJson = false | ||
|
||
const fs = require('fs') | ||
|
||
global.__global = { | ||
env: { | ||
|
||
URL: "http://localhost:5000", | ||
isProd: false, | ||
URL: 'http://localhost:5000', | ||
isProd: false | ||
// ...require('dotenv').config().parsed | ||
} | ||
} | ||
|
||
fetchMock.get( | ||
'https://flsshygn-lageso-berlin-prediction-merge-dev.s3.eu-central-1.amazonaws.com/app/data.csv', | ||
fs.readFileSync(__dirname + '/src/__tests__/data/data.csv', 'utf8') | ||
) | ||
'http://localhost:5000/.netlify/functions/swimapi', | ||
fs.readFileSync(__dirname + '/src/__tests__/data/data.json', 'utf8') | ||
) | ||
|
||
fetchMock.get( | ||
'http://localhost:5000/assets/data/new_build.csv', | ||
fs.readFileSync(__dirname + '/src/__tests__/data/new_build.csv', 'utf8') | ||
) | ||
) | ||
|
||
jest.mock('mapbox-gl/dist/mapbox-gl', () => { | ||
return { | ||
'default': { | ||
default: { | ||
accessToken: '', | ||
GeolocateControl: jest.fn(), | ||
Map: jest.fn(() => ({ | ||
addControl: jest.fn(), | ||
on: jest.fn(), | ||
remove: jest.fn(), | ||
fitBounds: jest.fn(), | ||
flyTo: jest.fn(), | ||
flyTo: jest.fn() | ||
})), | ||
NavigationControl: jest.fn(), | ||
Marker: jest.fn(() => ({ | ||
setLngLat: jest.fn(), | ||
addTo: jest.fn(), | ||
})), | ||
addTo: jest.fn() | ||
})) | ||
} | ||
} | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[[headers]] | ||
for = "/*" | ||
|
||
[headers.values] | ||
Access-Control-Allow-Origin = "*" | ||
Access-Control-Allow-Origin = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Context } from '@netlify/functions' | ||
|
||
export default async (req: Request, context: Context) => { | ||
const username = Netlify.env.get('SWIM_API_USER') | ||
const password = Netlify.env.get('SWIM_API_PASSWORD') | ||
const url = Netlify.env.get('SWIM_API_URL') | ||
if (!username || !password || !url) { | ||
return new Response('Missing required environment variables') | ||
} | ||
const auth = `Basic ${btoa(`${username}:${password}`)}` | ||
const options = { | ||
method: 'GET', | ||
headers: { | ||
Authorization: auth | ||
} | ||
} | ||
|
||
try { | ||
const response = await fetch(url, options) | ||
if (!response.ok) { | ||
return new Response('Failed to fetch data from Swim API', { | ||
status: response.status | ||
}) | ||
} | ||
const data = await response.json() | ||
const alteredData = data.map((m: any) => { | ||
const { id, badestellen_id } = m | ||
const item = { ...m, id: badestellen_id, swim_id: id } | ||
return item | ||
}) | ||
return new Response(JSON.stringify(alteredData), { | ||
headers: { | ||
'Access-Control-Allow-Origin': '*', // Allow from anywhere | ||
'Access-Control-Allow-Methods': 'GET', // Allow these HTTP methods | ||
'Access-Control-Allow-Headers': 'Content-Type', // Allow Content-Type header | ||
'content-type': 'application/json' | ||
} | ||
}) | ||
} catch (error) { | ||
console.error(error) | ||
return new Response('Failed to fetch data from Swim API', { status: 500 }) | ||
} | ||
} |
Oops, something went wrong.