Skip to content

Commit

Permalink
Update API paths (#291)
Browse files Browse the repository at this point in the history
* updates API path to go from api.bikehopper.com/ to bikehopper.org/api/
* update API to use generic paths instead of implementation specific paths (e.g. /photon -> /geocode)
* remove domain from API urls
  • Loading branch information
Andykmcc authored Dec 2, 2023
1 parent 4cfddc2 commit 69a0dfc
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/lib/BikehopperClient.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { DateTime } from 'luxon';

// Hardcoded list of API domains for different environments.
// TODO: Find a cleaner way to handle this, so people deploying their own
// instances on their own domains don't have to edit the source.
const API_DOMAINS = {
'https://staging.bikehopper.org': 'https://api-staging.bikehopper.org',
'https://bikehopper.org': 'https://api.bikehopper.org',
};

function getApiPath() {
const apiDomain = import.meta.env.VITE_API_DOMAIN;
const loc = document.location;
const protoAndHost = `${loc.protocol}//${loc.host}`;
// If not running on one of the above domains, default to making API requests
// to same domain, which is what we generally want for development.
return apiDomain || API_DOMAINS[protoAndHost] || '';
return apiDomain || '';
}

const POINT_PRECISION = 5;
Expand Down Expand Up @@ -65,7 +55,7 @@ export async function fetchRoute({
pt.map((coord) => coord.toFixed(POINT_PRECISION)),
);

let graphHopperPath = getApiPath() + '/v1/graphhopper';
let graphHopperPath = getApiPath() + '/api/v1/route';
if (import.meta.env.DEV && import.meta.env.VITE_USE_LOCAL_GRAPHHOPPER)
graphHopperPath = import.meta.env.VITE_USE_LOCAL_GRAPHHOPPER;

Expand Down Expand Up @@ -117,7 +107,7 @@ export async function geocode(
signal,
},
) {
let url = `${getApiPath()}/v1/photon/geocode?q=${encodeURIComponent(
let url = `${getApiPath()}/api/v1/geocode/geocode?q=${encodeURIComponent(
placeString,
)}&lang=${lang}&limit=${limit}`;

Expand Down

0 comments on commit 69a0dfc

Please sign in to comment.