diff --git a/flake.nix b/flake.nix
index 680cf6e..b524043 100644
--- a/flake.nix
+++ b/flake.nix
@@ -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";
diff --git a/nix/module-test.nix b/nix/module-test.nix
index 6e8b7f1..d938e88 100644
--- a/nix/module-test.nix
+++ b/nix/module-test.nix
@@ -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";
diff --git a/nix/module.nix b/nix/module.nix
index de81ed4..970235e 100644
--- a/nix/module.nix
+++ b/nix/module.nix
@@ -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;
+ '';
+ };
+ };
+ };
};
};
}
diff --git a/rest-api/db/migrations/20240810115846_image_upload_function.sql.sql b/rest-api/db/migrations/20240810115846_image_upload_function.sql.sql
index e3674b9..e6220d3 100644
--- a/rest-api/db/migrations/20240810115846_image_upload_function.sql.sql
+++ b/rest-api/db/migrations/20240810115846_image_upload_function.sql.sql
@@ -11,20 +11,24 @@ DECLARE
_allowed_mimetypes TEXT[] := ARRAY['image/png', 'image/svg+xml', 'image/jpeg', 'image/webp'];
_max_file_size INT := 5 * 1024 * 1024;
BEGIN
- IF _mimetype IS NULL OR _mimetype NOT IN (
- SELECT
- UNNEST(_allowed_mimetypes)) THEN
+ IF octet_length($1) = 0 THEN
RAISE invalid_parameter_value
- USING message = 'Invalid MIME type. Allowed types are: png, svg, jpg, webp';
+ USING message = 'No file data was provided';
END IF;
- IF OCTET_LENGTH($1) > _max_file_size THEN
- RAISE program_limit_exceeded
- USING message = FORMAT('File size exceeds the maximum limit of %s MB', _max_file_size / (1024 * 1024));
+ IF _mimetype IS NULL OR _mimetype NOT IN (
+ SELECT
+ UNNEST(_allowed_mimetypes)) THEN
+ RAISE invalid_parameter_value
+ USING message = 'Invalid MIME type. Allowed types are: png, svg, jpg, webp';
END IF;
- INSERT INTO internal.media (website_id, blob, mimetype, original_name)
- VALUES (_website_id, $1, _mimetype, _original_filename)
- RETURNING
- id INTO file_id;
+ IF OCTET_LENGTH($1) > _max_file_size THEN
+ RAISE program_limit_exceeded
+ USING message = FORMAT('File size exceeds the maximum limit of %s MB', _max_file_size / (1024 * 1024));
+ END IF;
+ INSERT INTO internal.media (website_id, blob, mimetype, original_name)
+ VALUES (_website_id, $1, _mimetype, _original_filename)
+ RETURNING
+ id INTO file_id;
END;
$$
LANGUAGE plpgsql
diff --git a/templates/blog/article.html b/templates/blog/article.html
index 542e558..cbe7888 100644
--- a/templates/blog/article.html
+++ b/templates/blog/article.html
@@ -3,6 +3,7 @@
+
Document
diff --git a/templates/blog/index.html b/templates/blog/index.html
index a973921..ecd8b3c 100644
--- a/templates/blog/index.html
+++ b/templates/blog/index.html
@@ -3,6 +3,7 @@
+
Document
diff --git a/templates/blog/styles.css b/templates/blog/styles.css
new file mode 100644
index 0000000..983fa49
--- /dev/null
+++ b/templates/blog/styles.css
@@ -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;
+}
\ No newline at end of file
diff --git a/web-app/.gitignore b/web-app/.gitignore
index f2b82b1..79518f7 100644
--- a/web-app/.gitignore
+++ b/web-app/.gitignore
@@ -1,6 +1,4 @@
node_modules
-user-uploads
-user-websites
# Output
.output
diff --git a/web-app/package.json b/web-app/package.json
index 9d981ed..9b3a689 100644
--- a/web-app/package.json
+++ b/web-app/package.json
@@ -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 .",
diff --git a/web-app/src/hooks.server.ts b/web-app/src/hooks.server.ts
index 0d39b66..9669b38 100644
--- a/web-app/src/hooks.server.ts
+++ b/web-app/src/hooks.server.ts
@@ -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",
diff --git a/web-app/src/routes/(anonymous)/login/+page.server.ts b/web-app/src/routes/(anonymous)/login/+page.server.ts
index 56df064..18dfdfc 100644
--- a/web-app/src/routes/(anonymous)/login/+page.server.ts
+++ b/web-app/src/routes/(anonymous)/login/+page.server.ts
@@ -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({
diff --git a/web-app/src/routes/(anonymous)/register/+page.server.ts b/web-app/src/routes/(anonymous)/register/+page.server.ts
index 6092b8c..1e6f447 100644
--- a/web-app/src/routes/(anonymous)/register/+page.server.ts
+++ b/web-app/src/routes/(anonymous)/register/+page.server.ts
@@ -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({
diff --git a/web-app/src/routes/(authenticated)/+page.server.ts b/web-app/src/routes/(authenticated)/+page.server.ts
index d71ab3b..bc0d0eb 100644
--- a/web-app/src/routes/(authenticated)/+page.server.ts
+++ b/web-app/src/routes/(authenticated)/+page.server.ts
@@ -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,17 +63,20 @@ export const actions: Actions = {
createWebsite: async ({ request, fetch, cookies }) => {
const data = await request.formData();
- const res = await fetch("http://localhost:3000/rpc/create_website", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${cookies.get("session_token")}`
- },
- body: JSON.stringify({
- content_type: data.get("content-type"),
- title: data.get("title")
- })
- });
+ const res = await fetch(
+ `http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/create_website`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${cookies.get("session_token")}`
+ },
+ body: JSON.stringify({
+ content_type: data.get("content-type"),
+ title: data.get("title")
+ })
+ }
+ );
if (!res.ok) {
const response = await res.json();
@@ -85,16 +88,19 @@ 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")}`, {
- method: "PATCH",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${cookies.get("session_token")}`
- },
- body: JSON.stringify({
- title: data.get("title")
- })
- });
+ const res = await fetch(
+ `http://localhost:${process.env.ARCHTIKA_API_PORT}/website?id=eq.${data.get("id")}`,
+ {
+ method: "PATCH",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${cookies.get("session_token")}`
+ },
+ 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")}`, {
- method: "DELETE",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${cookies.get("session_token")}`
+ 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();
diff --git a/web-app/src/routes/(authenticated)/account/+page.server.ts b/web-app/src/routes/(authenticated)/account/+page.server.ts
index 14391fb..6e1be1a 100644
--- a/web-app/src/routes/(authenticated)/account/+page.server.ts
+++ b/web-app/src/routes/(authenticated)/account/+page.server.ts
@@ -15,16 +15,19 @@ export const actions: Actions = {
deleteAccount: async ({ request, fetch, cookies }) => {
const data = await request.formData();
- const res = await fetch("http://localhost:3000/rpc/delete_account", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${cookies.get("session_token")}`
- },
- body: JSON.stringify({
- password: data.get("password")
- })
- });
+ const res = await fetch(
+ `http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/delete_account`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${cookies.get("session_token")}`
+ },
+ body: JSON.stringify({
+ password: data.get("password")
+ })
+ }
+ );
const response = await res.json();
diff --git a/web-app/src/routes/(authenticated)/website/[websiteId]/+layout.server.ts b/web-app/src/routes/(authenticated)/website/[websiteId]/+layout.server.ts
index afc55f1..630189f 100644
--- a/web-app/src/routes/(authenticated)/website/[websiteId]/+layout.server.ts
+++ b/web-app/src/routes/(authenticated)/website/[websiteId]/+layout.server.ts
@@ -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}`, {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${cookies.get("session_token")}`,
- Accept: "application/vnd.pgrst.object+json"
+ 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}`, {
- 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:${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();
diff --git a/web-app/src/routes/(authenticated)/website/[websiteId]/+page.server.ts b/web-app/src/routes/(authenticated)/website/[websiteId]/+page.server.ts
index d92eaf0..cd2d1d1 100644
--- a/web-app/src/routes/(authenticated)/website/[websiteId]/+page.server.ts
+++ b/web-app/src/routes/(authenticated)/website/[websiteId]/+page.server.ts
@@ -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();
diff --git a/web-app/src/routes/(authenticated)/website/[websiteId]/+page.svelte b/web-app/src/routes/(authenticated)/website/[websiteId]/+page.svelte
index 858e3eb..093cad8 100644
--- a/web-app/src/routes/(authenticated)/website/[websiteId]/+page.svelte
+++ b/web-app/src/routes/(authenticated)/website/[websiteId]/+page.svelte
@@ -56,7 +56,7 @@
{#if data.globalSettings.favicon_image}
@@ -110,7 +110,7 @@
{#if data.header.logo_image}
diff --git a/web-app/src/routes/(authenticated)/website/[websiteId]/articles/+page.server.ts b/web-app/src/routes/(authenticated)/website/[websiteId]/articles/+page.server.ts
index 250e1ed..a9fa4d7 100644
--- a/web-app/src/routes/(authenticated)/website/[websiteId]/articles/+page.server.ts
+++ b/web-app/src/routes/(authenticated)/website/[websiteId]/articles/+page.server.ts
@@ -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")}`, {
- method: "DELETE",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${cookies.get("session_token")}`
+ 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();
diff --git a/web-app/src/routes/(authenticated)/website/[websiteId]/articles/[articleId]/+page.server.ts b/web-app/src/routes/(authenticated)/website/[websiteId]/articles/[articleId]/+page.server.ts
index 9542669..9d7de32 100644
--- a/web-app/src/routes/(authenticated)/website/[websiteId]/articles/[articleId]/+page.server.ts
+++ b/web-app/src/routes/(authenticated)/website/[websiteId]/articles/[articleId]/+page.server.ts
@@ -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}`, {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${cookies.get("session_token")}`,
- Accept: "application/vnd.pgrst.object+json"
+ 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,40 +24,46 @@ 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`, {
- 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(
+ `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 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}`, {
- 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(
+ `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")
+ })
+ }
+ );
if (!res.ok) {
const response = await res.json();
diff --git a/web-app/src/routes/(authenticated)/website/[websiteId]/articles/[articleId]/+page.svelte b/web-app/src/routes/(authenticated)/website/[websiteId]/articles/[articleId]/+page.svelte
index 4d2941e..2de131d 100644
--- a/web-app/src/routes/(authenticated)/website/[websiteId]/articles/[articleId]/+page.svelte
+++ b/web-app/src/routes/(authenticated)/website/[websiteId]/articles/[articleId]/+page.svelte
@@ -69,7 +69,7 @@
{#if data.article.cover_image}
diff --git a/web-app/src/routes/(authenticated)/website/[websiteId]/collaborators/+page.server.ts b/web-app/src/routes/(authenticated)/website/[websiteId]/collaborators/+page.server.ts
index 504fb2d..f21467b 100644
--- a/web-app/src/routes/(authenticated)/website/[websiteId]/collaborators/+page.server.ts
+++ b/web-app/src/routes/(authenticated)/website/[websiteId]/collaborators/+page.server.ts
@@ -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: {
diff --git a/web-app/src/routes/(authenticated)/website/[websiteId]/publish/+page.server.ts b/web-app/src/routes/(authenticated)/website/[websiteId]/publish/+page.server.ts
index 834ed08..f36847e 100644
--- a/web-app/src/routes/(authenticated)/website/[websiteId]/publish/+page.server.ts
+++ b/web-app/src/routes/(authenticated)/website/[websiteId]/publish/+page.server.ts
@@ -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)
? `${websiteData.logo_text}`
: `
`
)
- .replace("{{cover_image}}", `
`)
+ .replace(
+ "{{cover_image}}",
+ `
`
+ )
.replace("{{title}}", `${article.title}
`)
.replace("{{publication_date}}", `${article.publication_date}
`)
.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);
};
diff --git a/web-app/src/routes/(authenticated)/website/[websiteId]/publish/+page.svelte b/web-app/src/routes/(authenticated)/website/[websiteId]/publish/+page.svelte
index a38f9a6..2e71c04 100644
--- a/web-app/src/routes/(authenticated)/website/[websiteId]/publish/+page.svelte
+++ b/web-app/src/routes/(authenticated)/website/[websiteId]/publish/+page.svelte
@@ -12,8 +12,7 @@