mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-26 12:01:45 +00:00
api server access in env
This commit is contained in:
parent
380e7191ed
commit
044bad3f60
2
Webserver/.env.example
Normal file
2
Webserver/.env.example
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
API_SERVER_IP=
|
||||||
|
API_SERVER_PORT=
|
5
Webserver/src/lib/server/buildAPIStr.ts
Normal file
5
Webserver/src/lib/server/buildAPIStr.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { API_SERVER_IP, API_SERVER_PORT } from '$env/static/private';
|
||||||
|
|
||||||
|
export function buildAPIStr(endpoint: string) {
|
||||||
|
return `http://${API_SERVER_IP ?? 'localhost'}:${API_SERVER_PORT ?? '8080'}/${endpoint}`;
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import type { APIResponse } from '$lib/interfaces';
|
import type { APIResponse } from '$lib/interfaces';
|
||||||
|
import { buildAPIStr } from '$lib/server/buildAPIStr';
|
||||||
import { json, type RequestHandler } from '@sveltejs/kit';
|
import { json, type RequestHandler } from '@sveltejs/kit';
|
||||||
|
|
||||||
// GET Endpoint for redirection API
|
// GET Endpoint for redirection API
|
||||||
@ -10,7 +11,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
|||||||
if (endpoint === null) return json({ success: false } as APIResponse);
|
if (endpoint === null) return json({ success: false } as APIResponse);
|
||||||
|
|
||||||
// Call API and respond with new data
|
// Call API and respond with new data
|
||||||
const api_call = await fetch(`http://localhost:8080/${endpoint}`);
|
const api_call = await fetch(buildAPIStr(endpoint));
|
||||||
const data = (await api_call.json()) as APIResponse;
|
const data = (await api_call.json()) as APIResponse;
|
||||||
return json(data);
|
return json(data);
|
||||||
};
|
};
|
||||||
@ -26,7 +27,7 @@ export const POST: RequestHandler = async ({ request }) => {
|
|||||||
// Remove endpoint to save on datatransfer
|
// Remove endpoint to save on datatransfer
|
||||||
formData.delete('endpoint');
|
formData.delete('endpoint');
|
||||||
// Call API and respond with new data
|
// Call API and respond with new data
|
||||||
const api_call = await fetch(`http://localhost:8080/${endpoint}`, {
|
const api_call = await fetch(buildAPIStr(endpoint.toString()), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
body: formData
|
body: formData
|
||||||
|
Loading…
Reference in New Issue
Block a user