Proxy API and webapp through NGINX as well

This commit is contained in:
thiloho
2024-08-13 22:14:47 +02:00
parent 6785bd0dfa
commit cf1600671b
18 changed files with 258 additions and 315 deletions

View File

@@ -67,7 +67,7 @@
web = { web = {
type = "app"; type = "app";
program = "${pkgs.writeShellScriptBin "web-wrapper" '' program = "${pkgs.writeShellScriptBin "web-wrapper" ''
ORIGIN=http://localhost:4000 HOST=127.0.0.1 PORT=4000 ARCHTIKA_API_PORT=3000 ARCHTIKA_NGINX_PORT=18000 ${pkgs.nodejs_22}/bin/node ${ ORIGIN=http://localhost:4000 HOST=127.0.0.1 PORT=4000 ${pkgs.nodejs_22}/bin/node ${
self.packages.${system}.default self.packages.${system}.default
}/web-app }/web-app
''}/bin/web-wrapper"; ''}/bin/web-wrapper";

View File

@@ -27,8 +27,8 @@
networkmanager.enable = true; networkmanager.enable = true;
firewall = { firewall = {
allowedTCPPorts = [ allowedTCPPorts = [
10000 80
15000 443
]; ];
}; };
}; };

View File

@@ -39,7 +39,7 @@
} }
{ {
from = "host"; from = "host";
host.port = 18000; host.port = 80;
guest.port = 80; guest.port = 80;
} }
]; ];

View File

@@ -50,12 +50,6 @@ in
default = 10000; default = 10000;
description = "Port on which the web application runs."; description = "Port on which the web application runs.";
}; };
nginxPort = mkOption {
type = types.port;
default = 15000;
description = "Port on which NGINX runs.";
};
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
@@ -110,7 +104,7 @@ in
}; };
script = '' script = ''
ORIGIN=http://localhost:${toString cfg.webAppPort} PORT=${toString cfg.webAppPort} ARCHTIKA_API_PORT=${toString cfg.port} ARCHTIKA_NGINX_PORT=${toString cfg.nginxPort} ${pkgs.nodejs_22}/bin/node ${cfg.package}/web-app ORIGIN=https://demo.archtika.com PORT=${toString cfg.webAppPort} ${pkgs.nodejs_22}/bin/node ${cfg.package}/web-app
''; '';
}; };
@@ -134,24 +128,40 @@ in
recommendedProxySettings = true; recommendedProxySettings = true;
recommendedTlsSettings = true; recommendedTlsSettings = true;
virtualHosts."archtika" = { virtualHosts = {
listen = [ "demo.archtika.com" = {
{ enableACME = true;
addr = "0.0.0.0"; forceSSL = true;
port = cfg.nginxPort;
}
];
locations = { locations = {
"/" = { "/" = {
root = "/var/www/archtika-websites"; proxyPass = "http://localhost:${toString cfg.webAppPort}";
};
"/user-websites/" = {
alias = "/var/www/archtika-websites/";
index = "index.html"; index = "index.html";
tryFiles = "$uri $uri/ $uri/index.html =404"; tryFiles = "$uri $uri/ $uri/index.html =404";
extraConfig = '' extraConfig = ''
autoindex on; autoindex on;
''; '';
}; };
"/api/" = {
proxyPass = "http://localhost:${toString cfg.port}/";
extraConfig = ''
default_type application/json;
proxy_hide_header Content-Location;
add_header Content-Location /api/$upstream_http_content_location;
proxy_set_header Connection "";
proxy_http_version 1.1;
'';
}; };
}; };
}; };
}; };
};
security.acme = {
acceptTerms = true;
defaults.email = "thilo.hohlt@tutanota.com";
};
};
} }

View File

@@ -3,9 +3,9 @@
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "ARCHTIKA_API_PORT=3000 ARCHTIKA_NGINX_PORT=18000 vite dev", "dev": "vite dev",
"build": "vite build", "build": "vite build",
"preview": "ARCHTIKA_API_PORT=3000 ARCHTIKA_NGINX_PORT=18000 vite preview", "preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check .", "lint": "prettier --check .",

View File

@@ -1,7 +1,8 @@
import { redirect } from "@sveltejs/kit"; import { redirect } from "@sveltejs/kit";
export const handle = async ({ event, resolve }) => { export const handle = async ({ event, resolve }) => {
const userData = await event.fetch(`http://localhost:${process.env.ARCHTIKA_API_PORT}/account`, { if (!event.url.pathname.startsWith("/api/")) {
const userData = await event.fetch(`/api/account`, {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -23,6 +24,7 @@ export const handle = async ({ event, resolve }) => {
event.locals.user = user; event.locals.user = user;
} }
}
return await resolve(event); return await resolve(event);
}; };

View File

@@ -4,7 +4,7 @@ export const actions: Actions = {
default: async ({ request, cookies, fetch }) => { default: async ({ request, cookies, fetch }) => {
const data = await request.formData(); const data = await request.formData();
const res = await fetch(`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/login`, { const res = await fetch(`/api/rpc/login`, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({

View File

@@ -4,7 +4,7 @@ export const actions: Actions = {
default: async ({ request, fetch }) => { default: async ({ request, fetch }) => {
const data = await request.formData(); const data = await request.formData();
const res = await fetch(`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/register`, { const res = await fetch(`/api/rpc/register`, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({

View File

@@ -6,7 +6,7 @@ export const load: PageServerLoad = async ({ fetch, cookies, url }) => {
const params = new URLSearchParams(); const params = new URLSearchParams();
const baseFetchUrl = `http://localhost:${process.env.ARCHTIKA_API_PORT}/website`; const baseFetchUrl = `/api/website`;
if (searchQuery) { if (searchQuery) {
params.append("title", `ilike.*${searchQuery}*`); params.append("title", `ilike.*${searchQuery}*`);
@@ -63,9 +63,7 @@ export const actions: Actions = {
createWebsite: async ({ request, fetch, cookies }) => { createWebsite: async ({ request, fetch, cookies }) => {
const data = await request.formData(); const data = await request.formData();
const res = await fetch( const res = await fetch(`/api/rpc/create_website`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/create_website`,
{
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -75,8 +73,7 @@ export const actions: Actions = {
content_type: data.get("content-type"), content_type: data.get("content-type"),
title: data.get("title") title: data.get("title")
}) })
} });
);
if (!res.ok) { if (!res.ok) {
const response = await res.json(); const response = await res.json();
@@ -88,9 +85,7 @@ export const actions: Actions = {
updateWebsite: async ({ request, cookies, fetch }) => { updateWebsite: async ({ request, cookies, fetch }) => {
const data = await request.formData(); const data = await request.formData();
const res = await fetch( const res = await fetch(`/api/website?id=eq.${data.get("id")}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/website?id=eq.${data.get("id")}`,
{
method: "PATCH", method: "PATCH",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -99,8 +94,7 @@ export const actions: Actions = {
body: JSON.stringify({ body: JSON.stringify({
title: data.get("title") title: data.get("title")
}) })
} });
);
if (!res.ok) { if (!res.ok) {
const response = await res.json(); const response = await res.json();
@@ -112,16 +106,13 @@ export const actions: Actions = {
deleteWebsite: async ({ request, cookies, fetch }) => { deleteWebsite: async ({ request, cookies, fetch }) => {
const data = await request.formData(); const data = await request.formData();
const res = await fetch( const res = await fetch(`/api/website?id=eq.${data.get("id")}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/website?id=eq.${data.get("id")}`,
{
method: "DELETE", method: "DELETE",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}` Authorization: `Bearer ${cookies.get("session_token")}`
} }
} });
);
if (!res.ok) { if (!res.ok) {
const response = await res.json(); const response = await res.json();

View File

@@ -15,9 +15,7 @@ export const actions: Actions = {
deleteAccount: async ({ request, fetch, cookies }) => { deleteAccount: async ({ request, fetch, cookies }) => {
const data = await request.formData(); const data = await request.formData();
const res = await fetch( const res = await fetch(`/api/rpc/delete_account`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/delete_account`,
{
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -26,8 +24,7 @@ export const actions: Actions = {
body: JSON.stringify({ body: JSON.stringify({
password: data.get("password") password: data.get("password")
}) })
} });
);
const response = await res.json(); const response = await res.json();

View File

@@ -1,29 +1,23 @@
import type { LayoutServerLoad } from "./$types"; import type { LayoutServerLoad } from "./$types";
export const load: LayoutServerLoad = async ({ params, fetch, cookies }) => { export const load: LayoutServerLoad = async ({ params, fetch, cookies }) => {
const websiteData = await fetch( const websiteData = await fetch(`/api/website?id=eq.${params.websiteId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/website?id=eq.${params.websiteId}`,
{
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`, Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json" Accept: "application/vnd.pgrst.object+json"
} }
} });
);
const homeData = await fetch( const homeData = await fetch(`/api/home?website_id=eq.${params.websiteId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/home?website_id=eq.${params.websiteId}`,
{
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`, Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json" Accept: "application/vnd.pgrst.object+json"
} }
} });
);
const website = await websiteData.json(); const website = await websiteData.json();
const home = await homeData.json(); const home = await homeData.json();

View File

@@ -1,41 +1,32 @@
import type { Actions, PageServerLoad } from "./$types"; import type { Actions, PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => { export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
const globalSettingsData = await fetch( const globalSettingsData = await fetch(`/api/settings?website_id=eq.${params.websiteId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/settings?website_id=eq.${params.websiteId}`,
{
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`, Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json" Accept: "application/vnd.pgrst.object+json"
} }
} });
);
const headerData = await fetch( const headerData = await fetch(`/api/header?website_id=eq.${params.websiteId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/header?website_id=eq.${params.websiteId}`,
{
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`, Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json" Accept: "application/vnd.pgrst.object+json"
} }
} });
);
const footerData = await fetch( const footerData = await fetch(`/api/footer?website_id=eq.${params.websiteId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/footer?website_id=eq.${params.websiteId}`,
{
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`, Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json" Accept: "application/vnd.pgrst.object+json"
} }
} });
);
const globalSettings = await globalSettingsData.json(); const globalSettings = await globalSettingsData.json();
const header = await headerData.json(); const header = await headerData.json();
@@ -53,9 +44,7 @@ export const actions: Actions = {
const data = await request.formData(); const data = await request.formData();
const faviconFile = data.get("favicon") as File; const faviconFile = data.get("favicon") as File;
const uploadedImageData = await fetch( const uploadedImageData = await fetch(`/api/rpc/upload_file`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/upload_file`,
{
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/octet-stream", "Content-Type": "application/octet-stream",
@@ -66,8 +55,7 @@ export const actions: Actions = {
"X-Original-Filename": faviconFile.name "X-Original-Filename": faviconFile.name
}, },
body: await faviconFile.arrayBuffer() body: await faviconFile.arrayBuffer()
} });
);
const uploadedImage = await uploadedImageData.json(); const uploadedImage = await uploadedImageData.json();
@@ -75,9 +63,7 @@ export const actions: Actions = {
return { success: false, message: uploadedImage.message }; return { success: false, message: uploadedImage.message };
} }
const res = await fetch( const res = await fetch(`/api/settings?website_id=eq.${params.websiteId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/settings?website_id=eq.${params.websiteId}`,
{
method: "PATCH", method: "PATCH",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -88,8 +74,7 @@ export const actions: Actions = {
accent_color_dark_theme: data.get("accent-color-dark"), accent_color_dark_theme: data.get("accent-color-dark"),
favicon_image: uploadedImage.file_id favicon_image: uploadedImage.file_id
}) })
} });
);
if (!res.ok) { if (!res.ok) {
const response = await res.json(); const response = await res.json();
@@ -105,9 +90,7 @@ export const actions: Actions = {
const data = await request.formData(); const data = await request.formData();
const logoImage = data.get("logo-image") as File; const logoImage = data.get("logo-image") as File;
const uploadedImageData = await fetch( const uploadedImageData = await fetch(`/api/rpc/upload_file`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/upload_file`,
{
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/octet-stream", "Content-Type": "application/octet-stream",
@@ -118,8 +101,7 @@ export const actions: Actions = {
"X-Original-Filename": logoImage.name "X-Original-Filename": logoImage.name
}, },
body: await logoImage.arrayBuffer() body: await logoImage.arrayBuffer()
} });
);
const uploadedImage = await uploadedImageData.json(); const uploadedImage = await uploadedImageData.json();
@@ -127,9 +109,7 @@ export const actions: Actions = {
return { success: false, message: uploadedImage.message }; return { success: false, message: uploadedImage.message };
} }
const res = await fetch( const res = await fetch(`/api/header?website_id=eq.${params.websiteId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/header?website_id=eq.${params.websiteId}`,
{
method: "PATCH", method: "PATCH",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -140,8 +120,7 @@ export const actions: Actions = {
logo_text: data.get("logo-text"), logo_text: data.get("logo-text"),
logo_image: uploadedImage.file_id logo_image: uploadedImage.file_id
}) })
} });
);
if (!res.ok) { if (!res.ok) {
const response = await res.json(); const response = await res.json();
@@ -156,9 +135,7 @@ export const actions: Actions = {
updateHome: async ({ request, fetch, cookies, params }) => { updateHome: async ({ request, fetch, cookies, params }) => {
const data = await request.formData(); const data = await request.formData();
const res = await fetch( const res = await fetch(`/api/home?website_id=eq.${params.websiteId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/home?website_id=eq.${params.websiteId}`,
{
method: "PATCH", method: "PATCH",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -167,8 +144,7 @@ export const actions: Actions = {
body: JSON.stringify({ body: JSON.stringify({
main_content: data.get("main-content") main_content: data.get("main-content")
}) })
} });
);
if (!res.ok) { if (!res.ok) {
const response = await res.json(); const response = await res.json();
@@ -180,9 +156,7 @@ export const actions: Actions = {
updateFooter: async ({ request, fetch, cookies, params }) => { updateFooter: async ({ request, fetch, cookies, params }) => {
const data = await request.formData(); const data = await request.formData();
const res = await fetch( const res = await fetch(`/api/footer?website_id=eq.${params.websiteId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/footer?website_id=eq.${params.websiteId}`,
{
method: "PATCH", method: "PATCH",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -191,8 +165,7 @@ export const actions: Actions = {
body: JSON.stringify({ body: JSON.stringify({
additional_text: data.get("additional-text") additional_text: data.get("additional-text")
}) })
} });
);
if (!res.ok) { if (!res.ok) {
const response = await res.json(); const response = await res.json();

View File

@@ -55,10 +55,7 @@
</label> </label>
{#if data.globalSettings.favicon_image} {#if data.globalSettings.favicon_image}
<Modal id="preview-favicon-global-{data.globalSettings.website_id}" text="Preview"> <Modal id="preview-favicon-global-{data.globalSettings.website_id}" text="Preview">
<img <img src={`/api/rpc/retrieve_file?id=${data.globalSettings.favicon_image}`} alt="" />
src={`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/retrieve_file?id=${data.globalSettings.favicon_image}`}
alt=""
/>
</Modal> </Modal>
{/if} {/if}
</div> </div>
@@ -109,10 +106,7 @@
</label> </label>
{#if data.header.logo_image} {#if data.header.logo_image}
<Modal id="preview-logo-header-{data.header.website_id}" text="Preview"> <Modal id="preview-logo-header-{data.header.website_id}" text="Preview">
<img <img src={`/api/rpc/retrieve_file?id=${data.header.logo_image}`} alt="" />
src={`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/retrieve_file?id=${data.header.logo_image}`}
alt=""
/>
</Modal> </Modal>
{/if} {/if}
</div> </div>

View File

@@ -6,7 +6,7 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent
const parameters = new URLSearchParams(); 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) { if (searchQuery) {
parameters.append("title", `ilike.*${searchQuery}*`); parameters.append("title", `ilike.*${searchQuery}*`);
@@ -66,7 +66,7 @@ export const actions: Actions = {
createArticle: async ({ request, fetch, cookies, params, locals }) => { createArticle: async ({ request, fetch, cookies, params, locals }) => {
const data = await request.formData(); 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", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -89,16 +89,13 @@ export const actions: Actions = {
deleteArticle: async ({ request, fetch, cookies }) => { deleteArticle: async ({ request, fetch, cookies }) => {
const data = await request.formData(); const data = await request.formData();
const res = await fetch( const res = await fetch(`/api/article?id=eq.${data.get("id")}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/article?id=eq.${data.get("id")}`,
{
method: "DELETE", method: "DELETE",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}` Authorization: `Bearer ${cookies.get("session_token")}`
} }
} });
);
if (!res.ok) { if (!res.ok) {
const response = await res.json(); const response = await res.json();

View File

@@ -1,17 +1,14 @@
import type { Actions, PageServerLoad } from "./$types"; import type { Actions, PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) => { export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) => {
const articleData = await fetch( const articleData = await fetch(`/api/article?id=eq.${params.articleId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/article?id=eq.${params.articleId}`,
{
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`, Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json" Accept: "application/vnd.pgrst.object+json"
} }
} });
);
const article = await articleData.json(); const article = await articleData.json();
const { website } = await parent(); const { website } = await parent();
@@ -24,9 +21,7 @@ export const actions: Actions = {
const data = await request.formData(); const data = await request.formData();
const coverFile = data.get("cover-image") as File; const coverFile = data.get("cover-image") as File;
const uploadedImageData = await fetch( const uploadedImageData = await fetch(`/api/rpc/upload_file`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/upload_file`,
{
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/octet-stream", "Content-Type": "application/octet-stream",
@@ -37,8 +32,7 @@ export const actions: Actions = {
"X-Original-Filename": coverFile.name "X-Original-Filename": coverFile.name
}, },
body: await coverFile.arrayBuffer() body: await coverFile.arrayBuffer()
} });
);
const uploadedImage = await uploadedImageData.json(); const uploadedImage = await uploadedImageData.json();
@@ -46,9 +40,7 @@ export const actions: Actions = {
return { success: false, message: uploadedImage.message }; return { success: false, message: uploadedImage.message };
} }
const res = await fetch( const res = await fetch(`/api/article?id=eq.${params.articleId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/article?id=eq.${params.articleId}`,
{
method: "PATCH", method: "PATCH",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -62,8 +54,7 @@ export const actions: Actions = {
publication_date: data.get("publication-date"), publication_date: data.get("publication-date"),
main_content: data.get("main-content") main_content: data.get("main-content")
}) })
} });
);
if (!res.ok) { if (!res.ok) {
const response = await res.json(); const response = await res.json();

View File

@@ -68,10 +68,7 @@
</label> </label>
{#if data.article.cover_image} {#if data.article.cover_image}
<Modal id="preview-cover-article-{data.article.id}" text="Preview"> <Modal id="preview-cover-article-{data.article.id}" text="Preview">
<img <img src={`/api/rpc/retrieve_file?id=${data.article.cover_image}`} alt="" />
src={`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/retrieve_file?id=${data.article.cover_image}`}
alt=""
/>
</Modal> </Modal>
{/if} {/if}
</div> </div>

View File

@@ -4,7 +4,7 @@ export const load: PageServerLoad = async ({ parent, params, fetch, cookies }) =
const { website, home } = await parent(); const { website, home } = await parent();
const collabData = await fetch( const collabData = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/collab?website_id=eq.${params.websiteId}&select=*,user!user_id(*)`, `/api/collab?website_id=eq.${params.websiteId}&select=*,user!user_id(*)`,
{ {
method: "GET", method: "GET",
headers: { headers: {
@@ -27,7 +27,7 @@ export const actions: Actions = {
addCollaborator: async ({ request, fetch, cookies, params }) => { addCollaborator: async ({ request, fetch, cookies, params }) => {
const data = await request.formData(); const data = await request.formData();
const res = await fetch(`http://localhost:${process.env.ARCHTIKA_API_PORT}/collab`, { const res = await fetch(`/api/collab`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -51,7 +51,7 @@ export const actions: Actions = {
const data = await request.formData(); const data = await request.formData();
const res = await fetch( const res = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`, `/api/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`,
{ {
method: "PATCH", method: "PATCH",
headers: { headers: {
@@ -75,7 +75,7 @@ export const actions: Actions = {
const data = await request.formData(); const data = await request.formData();
const res = await fetch( const res = await fetch(
`http://localhost:${process.env.ARCHTIKA_API_PORT}/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`, `/api/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`,
{ {
method: "DELETE", method: "DELETE",
headers: { headers: {

View File

@@ -4,23 +4,20 @@ import { md } from "$lib/utils";
import type { Actions, PageServerLoad } from "./$types"; import type { Actions, PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ params, fetch, cookies, locals }) => { export const load: PageServerLoad = async ({ params, fetch, cookies, locals }) => {
const websiteOverviewData = await fetch( const websiteOverviewData = await fetch(`/api/website_overview?id=eq.${params.websiteId}`, {
`http://localhost:${process.env.ARCHTIKA_API_PORT}/website_overview?id=eq.${params.websiteId}`,
{
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`, Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json" Accept: "application/vnd.pgrst.object+json"
} }
} });
);
const websiteOverview = await websiteOverviewData.json(); const websiteOverview = await websiteOverviewData.json();
generateStaticFiles(websiteOverview); generateStaticFiles(websiteOverview);
const websitePreviewUrl = `http://localhost:${process.env.ARCHTIKA_NGINX_PORT}/previews/${websiteOverview.user_id}/${websiteOverview.id}/index.html`; const websitePreviewUrl = `/user-websites/previews/${websiteOverview.user_id}/${websiteOverview.id}/index.html`;
return { return {
websiteOverview, websiteOverview,
@@ -125,7 +122,7 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
) )
.replace( .replace(
"{{cover_image}}", "{{cover_image}}",
`<img src="${article.cover_image ? `http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/retrieve_file?id=${article.cover_image}` : "https://picsum.photos/600/200"}" />` `<img src="${article.cover_image ? `/api/rpc/retrieve_file?id=${article.cover_image}` : "https://picsum.photos/600/200"}" />`
) )
.replace("{{title}}", `<h1>${article.title}</h1>`) .replace("{{title}}", `<h1>${article.title}</h1>`)
.replace("{{publication_date}}", `<p>${article.publication_date}</p>`) .replace("{{publication_date}}", `<p>${article.publication_date}</p>`)