Use environment variables for ports in web app

This commit is contained in:
thiloho
2024-08-10 22:20:57 +02:00
parent 0866e2631d
commit 162118bb56
23 changed files with 347 additions and 223 deletions

View File

@@ -2,7 +2,7 @@ import type { Actions, PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
const globalSettingsData = await fetch(
`http://localhost:3000/settings?website_id=eq.${params.websiteId}`,
`http://localhost:${process.env.ARCHTIKA_API_PORT}/settings?website_id=eq.${params.websiteId}`,
{
method: "GET",
headers: {
@@ -13,23 +13,29 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
}
);
const headerData = await fetch(`http://localhost:3000/header?website_id=eq.${params.websiteId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json"
const headerData = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/header?website_id=eq.${params.websiteId}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json"
}
}
});
);
const footerData = await fetch(`http://localhost:3000/footer?website_id=eq.${params.websiteId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json"
const footerData = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/footer?website_id=eq.${params.websiteId}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json"
}
}
});
);
const globalSettings = await globalSettingsData.json();
const header = await headerData.json();
@@ -47,37 +53,43 @@ export const actions: Actions = {
const data = await request.formData();
const faviconFile = data.get("favicon") as File;
const uploadedImageData = await fetch(`http://localhost:3000/rpc/upload_file`, {
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId,
"X-Mimetype": faviconFile.type,
"X-Original-Filename": faviconFile.name
},
body: await faviconFile.arrayBuffer()
});
const uploadedImageData = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/upload_file`,
{
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId,
"X-Mimetype": faviconFile.type,
"X-Original-Filename": faviconFile.name
},
body: await faviconFile.arrayBuffer()
}
);
const uploadedImage = await uploadedImageData.json();
if (!uploadedImageData.ok) {
if (!uploadedImageData.ok && faviconFile.size > 0) {
return { success: false, message: uploadedImage.message };
}
const res = await fetch(`http://localhost:3000/settings?website_id=eq.${params.websiteId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`
},
body: JSON.stringify({
accent_color_light_theme: data.get("accent-color-light"),
accent_color_dark_theme: data.get("accent-color-dark"),
favicon_image: uploadedImage.file_id
})
});
const res = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/settings?website_id=eq.${params.websiteId}`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`
},
body: JSON.stringify({
accent_color_light_theme: data.get("accent-color-light"),
accent_color_dark_theme: data.get("accent-color-dark"),
favicon_image: uploadedImage.file_id
})
}
);
if (!res.ok) {
const response = await res.json();
@@ -93,37 +105,43 @@ export const actions: Actions = {
const data = await request.formData();
const logoImage = data.get("logo-image") as File;
const uploadedImageData = await fetch(`http://localhost:3000/rpc/upload_file`, {
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId,
"X-Mimetype": logoImage.type,
"X-Original-Filename": logoImage.name
},
body: await logoImage.arrayBuffer()
});
const uploadedImageData = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/upload_file`,
{
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId,
"X-Mimetype": logoImage.type,
"X-Original-Filename": logoImage.name
},
body: await logoImage.arrayBuffer()
}
);
const uploadedImage = await uploadedImageData.json();
if (!uploadedImageData.ok) {
if (!uploadedImageData.ok && logoImage.size > 0) {
return { success: false, message: uploadedImage.message };
}
const res = await fetch(`http://localhost:3000/header?website_id=eq.${params.websiteId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`
},
body: JSON.stringify({
logo_type: data.get("logo-type"),
logo_text: data.get("logo-text"),
logo_image: uploadedImage.file_id
})
});
const res = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/header?website_id=eq.${params.websiteId}`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`
},
body: JSON.stringify({
logo_type: data.get("logo-type"),
logo_text: data.get("logo-text"),
logo_image: uploadedImage.file_id
})
}
);
if (!res.ok) {
const response = await res.json();
@@ -138,16 +156,19 @@ export const actions: Actions = {
updateHome: async ({ request, fetch, cookies, params }) => {
const data = await request.formData();
const res = await fetch(`http://localhost:3000/home?website_id=eq.${params.websiteId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`
},
body: JSON.stringify({
main_content: data.get("main-content")
})
});
const res = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/home?website_id=eq.${params.websiteId}`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`
},
body: JSON.stringify({
main_content: data.get("main-content")
})
}
);
if (!res.ok) {
const response = await res.json();
@@ -159,16 +180,19 @@ export const actions: Actions = {
updateFooter: async ({ request, fetch, cookies, params }) => {
const data = await request.formData();
const res = await fetch(`http://localhost:3000/footer?website_id=eq.${params.websiteId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`
},
body: JSON.stringify({
additional_text: data.get("additional-text")
})
});
const res = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/footer?website_id=eq.${params.websiteId}`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`
},
body: JSON.stringify({
additional_text: data.get("additional-text")
})
}
);
if (!res.ok) {
const response = await res.json();