mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 02:41:35 +01:00
Use environment variables for ports in web app
This commit is contained in:
@@ -67,7 +67,7 @@
|
||||
web = {
|
||||
type = "app";
|
||||
program = "${pkgs.writeShellScriptBin "web-wrapper" ''
|
||||
ORIGIN=http://localhost:4000 HOST=127.0.0.1 PORT=4000 ${pkgs.nodejs_22}/bin/node ${
|
||||
ORIGIN=http://localhost:4000 HOST=127.0.0.1 PORT=4000 ARCHTIKA_API_PORT=3000 ARCHTIKA_NGINX_PORT=18000 ${pkgs.nodejs_22}/bin/node ${
|
||||
self.packages.${system}.default
|
||||
}/web-app
|
||||
''}/bin/web-wrapper";
|
||||
|
||||
@@ -30,13 +30,18 @@
|
||||
forwardPorts = [
|
||||
{
|
||||
from = "host";
|
||||
host.port = 13000;
|
||||
guest.port = 3000;
|
||||
host.port = 5000;
|
||||
guest.port = 5000;
|
||||
}
|
||||
{
|
||||
from = "host";
|
||||
host.port = 14000;
|
||||
guest.port = 4000;
|
||||
host.port = 10000;
|
||||
guest.port = 10000;
|
||||
}
|
||||
{
|
||||
from = "host";
|
||||
host.port = 15000;
|
||||
guest.port = 15000;
|
||||
}
|
||||
];
|
||||
};
|
||||
@@ -44,7 +49,7 @@
|
||||
services.archtika = {
|
||||
enable = true;
|
||||
package = localArchtikaPackage;
|
||||
jwtSecret = "test-secret";
|
||||
jwtSecret = "a42kVyAhTImYxZeebZkApoAZLmf0VtDA";
|
||||
};
|
||||
|
||||
system.stateVersion = "24.05";
|
||||
|
||||
@@ -41,27 +41,33 @@ in
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 3000;
|
||||
default = 5000;
|
||||
description = "Port on which the API runs.";
|
||||
};
|
||||
|
||||
webAppPort = mkOption {
|
||||
type = types.port;
|
||||
default = 4000;
|
||||
default = 10000;
|
||||
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 {
|
||||
users.users.${cfg.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
home = "/var/lib/archtika";
|
||||
createHome = true;
|
||||
};
|
||||
|
||||
users.groups.${cfg.group} = { };
|
||||
|
||||
systemd.tmpfiles.rules = [ "d /var/www/archtika-websites 0755 ${cfg.user} ${cfg.group} -" ];
|
||||
|
||||
systemd.services.archtika-api = {
|
||||
description = "archtika API service";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
@@ -97,7 +103,7 @@ in
|
||||
};
|
||||
|
||||
script = ''
|
||||
ORIGIN=http://localhost:${toString cfg.webAppPort} PORT=${toString cfg.webAppPort} ${pkgs.nodejs_22}/bin/node ${cfg.package}/web-app
|
||||
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
|
||||
'';
|
||||
};
|
||||
|
||||
@@ -120,6 +126,25 @@ in
|
||||
enable = true;
|
||||
recommendedProxySettings = true;
|
||||
recommendedTlsSettings = true;
|
||||
|
||||
virtualHosts."_" = {
|
||||
listen = [
|
||||
{
|
||||
addr = "0.0.0.0";
|
||||
port = cfg.nginxPort;
|
||||
}
|
||||
];
|
||||
locations = {
|
||||
"/" = {
|
||||
root = "/var/www/archtika-websites";
|
||||
index = "index.html";
|
||||
tryFiles = "$uri $uri/ $uri/index.html =404";
|
||||
extraConfig = ''
|
||||
autoindex on;
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ DECLARE
|
||||
_allowed_mimetypes TEXT[] := ARRAY['image/png', 'image/svg+xml', 'image/jpeg', 'image/webp'];
|
||||
_max_file_size INT := 5 * 1024 * 1024;
|
||||
BEGIN
|
||||
IF octet_length($1) = 0 THEN
|
||||
RAISE invalid_parameter_value
|
||||
USING message = 'No file data was provided';
|
||||
END IF;
|
||||
IF _mimetype IS NULL OR _mimetype NOT IN (
|
||||
SELECT
|
||||
UNNEST(_allowed_mimetypes)) THEN
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="../styles.css">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
18
templates/blog/styles.css
Normal file
18
templates/blog/styles.css
Normal file
@@ -0,0 +1,18 @@
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
}
|
||||
|
||||
body {
|
||||
margin-inline: auto;
|
||||
inline-size: min(100% - 2rem, 75ch);
|
||||
line-height: 1.5;
|
||||
font-family: system-ui, sans-serif;
|
||||
}
|
||||
|
||||
img,
|
||||
picture,
|
||||
svg,
|
||||
video {
|
||||
max-inline-size: 100%;
|
||||
block-size: auto;
|
||||
}
|
||||
2
web-app/.gitignore
vendored
2
web-app/.gitignore
vendored
@@ -1,6 +1,4 @@
|
||||
node_modules
|
||||
user-uploads
|
||||
user-websites
|
||||
|
||||
# Output
|
||||
.output
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"dev": "ARCHTIKA_API_PORT=3000 ARCHTIKA_NGINX_PORT=18000 vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"preview": "ARCHTIKA_API_PORT=3000 ARCHTIKA_NGINX_PORT=18000 vite preview",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"lint": "prettier --check .",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
|
||||
export const handle = async ({ event, resolve }) => {
|
||||
const userData = await event.fetch("http://localhost:3000/account", {
|
||||
const userData = await event.fetch(`http://localhost:${process.env.ARCHTIKA_API_PORT}/account`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -4,7 +4,7 @@ export const actions: Actions = {
|
||||
default: async ({ request, cookies, fetch }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch("http://localhost:3000/rpc/login", {
|
||||
const res = await fetch(`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/login`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
|
||||
@@ -4,7 +4,7 @@ export const actions: Actions = {
|
||||
default: async ({ request, fetch }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch("http://localhost:3000/rpc/register", {
|
||||
const res = await fetch(`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/register`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
|
||||
@@ -6,7 +6,7 @@ export const load: PageServerLoad = async ({ fetch, cookies, url }) => {
|
||||
|
||||
const params = new URLSearchParams();
|
||||
|
||||
const baseFetchUrl = "http://localhost:3000/website";
|
||||
const baseFetchUrl = `http://localhost:${process.env.ARCHTIKA_API_PORT}/website`;
|
||||
|
||||
if (searchQuery) {
|
||||
params.append("title", `ilike.*${searchQuery}*`);
|
||||
@@ -63,7 +63,9 @@ export const actions: Actions = {
|
||||
createWebsite: async ({ request, fetch, cookies }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch("http://localhost:3000/rpc/create_website", {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/create_website`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -73,7 +75,8 @@ export const actions: Actions = {
|
||||
content_type: data.get("content-type"),
|
||||
title: data.get("title")
|
||||
})
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
@@ -85,7 +88,9 @@ export const actions: Actions = {
|
||||
updateWebsite: async ({ request, cookies, fetch }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch(`http://localhost:3000/website?id=eq.${data.get("id")}`, {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/website?id=eq.${data.get("id")}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -94,7 +99,8 @@ export const actions: Actions = {
|
||||
body: JSON.stringify({
|
||||
title: data.get("title")
|
||||
})
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
@@ -106,13 +112,16 @@ export const actions: Actions = {
|
||||
deleteWebsite: async ({ request, cookies, fetch }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch(`http://localhost:3000/website?id=eq.${data.get("id")}`, {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/website?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();
|
||||
|
||||
@@ -15,7 +15,9 @@ export const actions: Actions = {
|
||||
deleteAccount: async ({ request, fetch, cookies }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch("http://localhost:3000/rpc/delete_account", {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/delete_account`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -24,7 +26,8 @@ export const actions: Actions = {
|
||||
body: JSON.stringify({
|
||||
password: data.get("password")
|
||||
})
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
const response = await res.json();
|
||||
|
||||
|
||||
@@ -1,23 +1,29 @@
|
||||
import type { LayoutServerLoad } from "./$types";
|
||||
|
||||
export const load: LayoutServerLoad = async ({ params, fetch, cookies }) => {
|
||||
const websiteData = await fetch(`http://localhost:3000/website?id=eq.${params.websiteId}`, {
|
||||
const websiteData = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/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 homeData = await fetch(`http://localhost:3000/home?website_id=eq.${params.websiteId}`, {
|
||||
const homeData = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/home?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 website = await websiteData.json();
|
||||
const home = await homeData.json();
|
||||
|
||||
@@ -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}`, {
|
||||
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}`, {
|
||||
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,7 +53,9 @@ 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`, {
|
||||
const uploadedImageData = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/upload_file`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/octet-stream",
|
||||
@@ -58,15 +66,18 @@ export const actions: Actions = {
|
||||
"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}`, {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/settings?website_id=eq.${params.websiteId}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -77,7 +88,8 @@ export const actions: Actions = {
|
||||
accent_color_dark_theme: data.get("accent-color-dark"),
|
||||
favicon_image: uploadedImage.file_id
|
||||
})
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
@@ -93,7 +105,9 @@ 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`, {
|
||||
const uploadedImageData = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/upload_file`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/octet-stream",
|
||||
@@ -104,15 +118,18 @@ export const actions: Actions = {
|
||||
"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}`, {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/header?website_id=eq.${params.websiteId}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -123,7 +140,8 @@ export const actions: Actions = {
|
||||
logo_text: data.get("logo-text"),
|
||||
logo_image: uploadedImage.file_id
|
||||
})
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
@@ -138,7 +156,9 @@ 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}`, {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/home?website_id=eq.${params.websiteId}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -147,7 +167,8 @@ export const actions: Actions = {
|
||||
body: JSON.stringify({
|
||||
main_content: data.get("main-content")
|
||||
})
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
@@ -159,7 +180,9 @@ 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}`, {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/footer?website_id=eq.${params.websiteId}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -168,7 +191,8 @@ export const actions: Actions = {
|
||||
body: JSON.stringify({
|
||||
additional_text: data.get("additional-text")
|
||||
})
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
{#if data.globalSettings.favicon_image}
|
||||
<Modal id="preview-favicon-global-{data.globalSettings.website_id}" text="Preview">
|
||||
<img
|
||||
src={`http://localhost:3000/rpc/retrieve_file?id=${data.globalSettings.favicon_image}`}
|
||||
src={`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/retrieve_file?id=${data.globalSettings.favicon_image}`}
|
||||
alt=""
|
||||
/>
|
||||
</Modal>
|
||||
@@ -110,7 +110,7 @@
|
||||
{#if data.header.logo_image}
|
||||
<Modal id="preview-logo-header-{data.header.website_id}" text="Preview">
|
||||
<img
|
||||
src={`http://localhost:3000/rpc/retrieve_file?id=${data.header.logo_image}`}
|
||||
src={`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/retrieve_file?id=${data.header.logo_image}`}
|
||||
alt=""
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
@@ -6,7 +6,7 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent
|
||||
|
||||
const parameters = new URLSearchParams();
|
||||
|
||||
const baseFetchUrl = `http://localhost:3000/article?website_id=eq.${params.websiteId}&select=id,title`;
|
||||
const baseFetchUrl = `http://localhost:${process.env.ARCHTIKA_API_PORT}/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:3000/article", {
|
||||
const res = await fetch(`http://localhost:${process.env.ARCHTIKA_API_PORT}/article`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -89,13 +89,16 @@ export const actions: Actions = {
|
||||
deleteArticle: async ({ request, fetch, cookies }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch(`http://localhost:3000/article?id=eq.${data.get("id")}`, {
|
||||
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")}`
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
|
||||
export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) => {
|
||||
const articleData = await fetch(`http://localhost:3000/article?id=eq.${params.articleId}`, {
|
||||
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 article = await articleData.json();
|
||||
const { website } = await parent();
|
||||
@@ -21,7 +24,9 @@ export const actions: Actions = {
|
||||
const data = await request.formData();
|
||||
const coverFile = data.get("cover-image") as File;
|
||||
|
||||
const uploadedImageData = await fetch(`http://localhost:3000/rpc/upload_file`, {
|
||||
const uploadedImageData = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/upload_file`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/octet-stream",
|
||||
@@ -32,15 +37,18 @@ export const actions: Actions = {
|
||||
"X-Original-Filename": coverFile.name
|
||||
},
|
||||
body: await coverFile.arrayBuffer()
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
const uploadedImage = await uploadedImageData.json();
|
||||
|
||||
if (!uploadedImageData.ok) {
|
||||
if (!uploadedImageData.ok && coverFile.size > 0) {
|
||||
return { success: false, message: uploadedImage.message };
|
||||
}
|
||||
|
||||
const res = await fetch(`http://localhost:3000/article?id=eq.${params.articleId}`, {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/article?id=eq.${params.articleId}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -54,7 +62,8 @@ export const actions: Actions = {
|
||||
publication_date: data.get("publication-date"),
|
||||
main_content: data.get("main-content")
|
||||
})
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
{#if data.article.cover_image}
|
||||
<Modal id="preview-cover-article-{data.article.id}" text="Preview">
|
||||
<img
|
||||
src={`http://localhost:3000/rpc/retrieve_file?id=${data.article.cover_image}`}
|
||||
src={`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/retrieve_file?id=${data.article.cover_image}`}
|
||||
alt=""
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
@@ -4,7 +4,7 @@ export const load: PageServerLoad = async ({ parent, params, fetch, cookies }) =
|
||||
const { website, home } = await parent();
|
||||
|
||||
const collabData = await fetch(
|
||||
`http://localhost:3000/collab?website_id=eq.${params.websiteId}&select=*,user!user_id(*)`,
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/collab?website_id=eq.${params.websiteId}&select=*,user!user_id(*)`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
@@ -27,7 +27,7 @@ export const actions: Actions = {
|
||||
addCollaborator: async ({ request, fetch, cookies, params }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch("http://localhost:3000/collab", {
|
||||
const res = await fetch(`http://localhost:${process.env.ARCHTIKA_API_PORT}/collab`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -51,7 +51,7 @@ export const actions: Actions = {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch(
|
||||
`http://localhost:3000/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`,
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
@@ -75,7 +75,7 @@ export const actions: Actions = {
|
||||
const data = await request.formData();
|
||||
|
||||
const res = await fetch(
|
||||
`http://localhost:3000/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`,
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { Actions, PageServerLoad } from "./$types";
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch, cookies, locals }) => {
|
||||
const websiteOverviewData = await fetch(
|
||||
`http://localhost:3000/website_overview?id=eq.${params.websiteId}`,
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/website_overview?id=eq.${params.websiteId}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
@@ -20,17 +20,22 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, locals }) =
|
||||
|
||||
generateStaticFiles(websiteOverview);
|
||||
|
||||
const websitePreviewUrl = `http://localhost:${process.env.ARCHTIKA_NGINX_PORT}/previews/${websiteOverview.user_id}/${websiteOverview.id}/index.html`;
|
||||
|
||||
return {
|
||||
websiteOverview
|
||||
websiteOverview,
|
||||
websitePreviewUrl
|
||||
};
|
||||
};
|
||||
|
||||
export const actions: Actions = {
|
||||
publishWebsite: async ({ request, params, locals }) => {
|
||||
publishWebsite: async ({ request }) => {
|
||||
const data = await request.formData();
|
||||
const websiteOverview = JSON.parse(data.get("website-overview") as string);
|
||||
|
||||
generateStaticFiles(websiteOverview, false);
|
||||
|
||||
return { success: true, message: "Successfully published website" };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -46,6 +51,7 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
||||
const articleFile = await readFile(join(templatePath, "article.html"), {
|
||||
encoding: "utf-8"
|
||||
});
|
||||
const stylesFile = await readFile(join(templatePath, "styles.css"), { encoding: "utf-8" });
|
||||
|
||||
const indexFileContents = indexFile
|
||||
.replace(
|
||||
@@ -88,7 +94,15 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
||||
let uploadDir = "";
|
||||
|
||||
if (isPreview) {
|
||||
uploadDir = join(process.cwd(), "static", "user-websites", websiteData.user_id, websiteData.id);
|
||||
uploadDir = join(
|
||||
"/",
|
||||
"var",
|
||||
"www",
|
||||
"archtika-websites",
|
||||
"previews",
|
||||
websiteData.user_id,
|
||||
websiteData.id
|
||||
);
|
||||
} else {
|
||||
uploadDir = join("/", "var", "www", "archtika-websites", websiteData.user_id, websiteData.id);
|
||||
}
|
||||
@@ -109,7 +123,10 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
||||
? `<strong>${websiteData.logo_text}</strong>`
|
||||
: `<img src="https://picsum.photos/32/32" />`
|
||||
)
|
||||
.replace("{{cover_image}}", `<img src="https://picsum.photos/600/200" />`)
|
||||
.replace(
|
||||
"{{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"}" />`
|
||||
)
|
||||
.replace("{{title}}", `<h1>${article.title}</h1>`)
|
||||
.replace("{{publication_date}}", `<p>${article.publication_date}</p>`)
|
||||
.replace("{{main_content}}", md.render(article.main_content ?? ""))
|
||||
@@ -117,4 +134,6 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
||||
|
||||
await writeFile(join(uploadDir, "articles", `${articleFileName}.html`), articleFileContents);
|
||||
}
|
||||
|
||||
await writeFile(join(uploadDir, "styles.css"), stylesFile);
|
||||
};
|
||||
|
||||
@@ -12,8 +12,7 @@
|
||||
<WebsiteEditor
|
||||
id={data.website.id}
|
||||
title={data.website.title}
|
||||
previewContent="http://localhost:5173/user-websites/{data.websiteOverview.user_id}/{data
|
||||
.websiteOverview.id}/index.html"
|
||||
previewContent={data.websitePreviewUrl}
|
||||
fullPreview={true}
|
||||
>
|
||||
<section>
|
||||
|
||||
Reference in New Issue
Block a user