mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 10:51:36 +01:00
Proxy API and webapp through NGINX as well
This commit is contained in:
@@ -6,7 +6,7 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent
|
||||
|
||||
const parameters = new URLSearchParams();
|
||||
|
||||
const baseFetchUrl = `http://localhost:${process.env.ARCHTIKA_API_PORT}/article?website_id=eq.${params.websiteId}&select=id,title`;
|
||||
const baseFetchUrl = `/api/article?website_id=eq.${params.websiteId}&select=id,title`;
|
||||
|
||||
if (searchQuery) {
|
||||
parameters.append("title", `ilike.*${searchQuery}*`);
|
||||
@@ -66,7 +66,7 @@ export const actions: Actions = {
|
||||
createArticle: async ({ request, fetch, cookies, params, locals }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch(`http://localhost:${process.env.ARCHTIKA_API_PORT}/article`, {
|
||||
const res = await fetch(`/api/article`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -89,16 +89,13 @@ export const actions: Actions = {
|
||||
deleteArticle: async ({ request, fetch, cookies }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/article?id=eq.${data.get("id")}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`
|
||||
}
|
||||
const res = await fetch(`/api/article?id=eq.${data.get("id")}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
|
||||
export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) => {
|
||||
const articleData = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/article?id=eq.${params.articleId}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`,
|
||||
Accept: "application/vnd.pgrst.object+json"
|
||||
}
|
||||
const articleData = await fetch(`/api/article?id=eq.${params.articleId}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`,
|
||||
Accept: "application/vnd.pgrst.object+json"
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const article = await articleData.json();
|
||||
const { website } = await parent();
|
||||
@@ -24,21 +21,18 @@ export const actions: Actions = {
|
||||
const data = await request.formData();
|
||||
const coverFile = data.get("cover-image") as File;
|
||||
|
||||
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": coverFile.type,
|
||||
"X-Original-Filename": coverFile.name
|
||||
},
|
||||
body: await coverFile.arrayBuffer()
|
||||
}
|
||||
);
|
||||
const uploadedImageData = await fetch(`/api/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": coverFile.type,
|
||||
"X-Original-Filename": coverFile.name
|
||||
},
|
||||
body: await coverFile.arrayBuffer()
|
||||
});
|
||||
|
||||
const uploadedImage = await uploadedImageData.json();
|
||||
|
||||
@@ -46,24 +40,21 @@ export const actions: Actions = {
|
||||
return { success: false, message: uploadedImage.message };
|
||||
}
|
||||
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/article?id=eq.${params.articleId}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
title: data.get("title"),
|
||||
meta_description: data.get("description"),
|
||||
meta_author: data.get("author"),
|
||||
cover_image: uploadedImage.file_id,
|
||||
publication_date: data.get("publication-date"),
|
||||
main_content: data.get("main-content")
|
||||
})
|
||||
}
|
||||
);
|
||||
const res = await fetch(`/api/article?id=eq.${params.articleId}`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
title: data.get("title"),
|
||||
meta_description: data.get("description"),
|
||||
meta_author: data.get("author"),
|
||||
cover_image: uploadedImage.file_id,
|
||||
publication_date: data.get("publication-date"),
|
||||
main_content: data.get("main-content")
|
||||
})
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
|
||||
@@ -68,10 +68,7 @@
|
||||
</label>
|
||||
{#if data.article.cover_image}
|
||||
<Modal id="preview-cover-article-{data.article.id}" text="Preview">
|
||||
<img
|
||||
src={`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/retrieve_file?id=${data.article.cover_image}`}
|
||||
alt=""
|
||||
/>
|
||||
<img src={`/api/rpc/retrieve_file?id=${data.article.cover_image}`} alt="" />
|
||||
</Modal>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user