-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b8ebd7
commit d22673c
Showing
6 changed files
with
38 additions
and
2 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 +1,5 @@ | ||
API_URI=http://localhost:3030 # server reachable | ||
PUBLIC_API_URI=http://localhost:3030 # client reachable | ||
# use local frontend with official backend (CORS is enabled for http://localhost:5173) | ||
# API_URI=https://api.hearch.co | ||
# PUBLIC_API_URI=https://api.hearch.co |
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
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
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,10 @@ | ||
import { env } from '$env/dynamic/public'; | ||
|
||
export function createPublicApiUrl(path: string, params?: string): string { | ||
const apiUri: string | undefined = env.PUBLIC_API_URI; | ||
if (apiUri === undefined) { | ||
throw new Error('PUBLIC_API_URI env is not defined'); | ||
} | ||
|
||
return (apiUri.endsWith('/') ? apiUri : apiUri + '/') + path + (params ? `?${params}` : ''); | ||
} |
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,16 @@ | ||
import { error } from '@sveltejs/kit'; | ||
import { createPublicApiUrl } from '$lib/functions/createPublicApiUrl'; | ||
|
||
export function proxyImageLink(url: string, hash: string): string { | ||
const params: string = 'url=' + encodeURIComponent(url) + '&hash=' + hash; | ||
|
||
let apiUrl: string; | ||
try { | ||
apiUrl = createPublicApiUrl('proxy', params); | ||
} catch (err: any) { | ||
// Internal Server Error | ||
throw error(500, `Failed to create API URL: ${err.message}`); | ||
} | ||
|
||
return apiUrl; | ||
} |
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