mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 10:51:36 +01:00
Differentiate between dev and prod for api and nginx
This commit is contained in:
23
flake.nix
23
flake.nix
@@ -38,7 +38,6 @@
|
|||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
module-test = self.nixosConfigurations.module-test.config.system.build.vm;
|
|
||||||
dev-vm = self.nixosConfigurations.dev-vm.config.system.build.vm;
|
dev-vm = self.nixosConfigurations.dev-vm.config.system.build.vm;
|
||||||
|
|
||||||
default = pkgs.callPackage ./nix/package.nix { };
|
default = pkgs.callPackage ./nix/package.nix { };
|
||||||
@@ -56,33 +55,17 @@
|
|||||||
program = "${pkgs.writeShellScriptBin "api-setup" ''
|
program = "${pkgs.writeShellScriptBin "api-setup" ''
|
||||||
${pkgs.postgresql_16}/bin/psql postgres://postgres@localhost:15432/archtika -c "ALTER DATABASE archtika SET \"app.jwt_secret\" TO 'a42kVyAhTImYxZeebZkApoAZLmf0VtDA'"
|
${pkgs.postgresql_16}/bin/psql postgres://postgres@localhost:15432/archtika -c "ALTER DATABASE archtika SET \"app.jwt_secret\" TO 'a42kVyAhTImYxZeebZkApoAZLmf0VtDA'"
|
||||||
|
|
||||||
${pkgs.dbmate}/bin/dbmate --url postgres://postgres@localhost:15432/archtika?sslmode=disable --migrations-dir ${
|
echo "OUT PATH: ${self.outPath}"
|
||||||
self.packages.${system}.default
|
|
||||||
}/rest-api/db/migrations up
|
${pkgs.dbmate}/bin/dbmate --url postgres://postgres@localhost:15432/archtika?sslmode=disable --migrations-dir ${self.outPath}/rest-api/db/migrations up
|
||||||
|
|
||||||
PGRST_DB_SCHEMAS="api" PGRST_DB_ANON_ROLE="anon" PGRST_OPENAPI_MODE="ignore-privileges" PGRST_DB_URI="postgres://authenticator@localhost:15432/archtika" PGRST_JWT_SECRET="a42kVyAhTImYxZeebZkApoAZLmf0VtDA" ${pkgs.postgrest}/bin/postgrest
|
PGRST_DB_SCHEMAS="api" PGRST_DB_ANON_ROLE="anon" PGRST_OPENAPI_MODE="ignore-privileges" PGRST_DB_URI="postgres://authenticator@localhost:15432/archtika" PGRST_JWT_SECRET="a42kVyAhTImYxZeebZkApoAZLmf0VtDA" ${pkgs.postgrest}/bin/postgrest
|
||||||
''}/bin/api-setup";
|
''}/bin/api-setup";
|
||||||
};
|
};
|
||||||
|
|
||||||
web = {
|
|
||||||
type = "app";
|
|
||||||
program = "${pkgs.writeShellScriptBin "web-wrapper" ''
|
|
||||||
ORIGIN=http://localhost:4000 HOST=127.0.0.1 PORT=4000 ${pkgs.nodejs_22}/bin/node ${
|
|
||||||
self.packages.${system}.default
|
|
||||||
}/web-app
|
|
||||||
''}/bin/web-wrapper";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
nixosConfigurations = {
|
nixosConfigurations = {
|
||||||
module-test = nixpkgs.lib.nixosSystem {
|
|
||||||
system = "x86_64-linux";
|
|
||||||
modules = [
|
|
||||||
./nix/module-test.nix
|
|
||||||
{ _module.args.localArchtikaPackage = self.packages."x86_64-linux".default; }
|
|
||||||
];
|
|
||||||
};
|
|
||||||
dev-vm = nixpkgs.lib.nixosSystem {
|
dev-vm = nixpkgs.lib.nixosSystem {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
modules = [ ./nix/dev-vm.nix ];
|
modules = [ ./nix/dev-vm.nix ];
|
||||||
|
|||||||
@@ -39,8 +39,8 @@
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
from = "host";
|
from = "host";
|
||||||
host.port = 80;
|
host.port = 18000;
|
||||||
guest.port = 80;
|
guest.port = 1800;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
listen = [
|
listen = [
|
||||||
{
|
{
|
||||||
addr = "0.0.0.0";
|
addr = "0.0.0.0";
|
||||||
port = 80;
|
port = 1800;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
locations = {
|
locations = {
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
{
|
|
||||||
pkgs,
|
|
||||||
lib,
|
|
||||||
modulesPath,
|
|
||||||
localArchtikaPackage,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
"${modulesPath}/virtualisation/qemu-vm.nix"
|
|
||||||
./module.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
networking = {
|
|
||||||
hostName = "archtika-module-test";
|
|
||||||
firewall.enable = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
nix.settings.experimental-features = [ "nix-command flakes" ];
|
|
||||||
|
|
||||||
users.users.dev = {
|
|
||||||
isNormalUser = true;
|
|
||||||
extraGroups = [ "wheel" ];
|
|
||||||
password = "dev";
|
|
||||||
};
|
|
||||||
|
|
||||||
virtualisation = {
|
|
||||||
graphics = false;
|
|
||||||
# Alternatively a bridge network for QEMU could be setup, but requires much more effort
|
|
||||||
forwardPorts = [
|
|
||||||
{
|
|
||||||
from = "host";
|
|
||||||
host.port = 5000;
|
|
||||||
guest.port = 5000;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
from = "host";
|
|
||||||
host.port = 10000;
|
|
||||||
guest.port = 10000;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
from = "host";
|
|
||||||
host.port = 15000;
|
|
||||||
guest.port = 15000;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
services.archtika = {
|
|
||||||
enable = true;
|
|
||||||
package = localArchtikaPackage;
|
|
||||||
jwtSecret = "a42kVyAhTImYxZeebZkApoAZLmf0VtDA";
|
|
||||||
};
|
|
||||||
|
|
||||||
system.stateVersion = "24.05";
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { redirect } from "@sveltejs/kit";
|
import { redirect } from "@sveltejs/kit";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const handle = async ({ event, resolve }) => {
|
export const handle = async ({ event, resolve }) => {
|
||||||
if (!event.url.pathname.startsWith("/api/")) {
|
if (!event.url.pathname.startsWith("/api/")) {
|
||||||
const userData = await event.fetch(`/api/account`, {
|
const userData = await event.fetch(`${API_BASE_PREFIX}/account`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import markdownit from "markdown-it";
|
import markdownit from "markdown-it";
|
||||||
import hljs from "highlight.js";
|
import hljs from "highlight.js";
|
||||||
|
import { dev } from "$app/environment";
|
||||||
|
|
||||||
export const sortOptions = [
|
export const sortOptions = [
|
||||||
{ value: "creation-time", text: "Creation time" },
|
{ value: "creation-time", text: "Creation time" },
|
||||||
@@ -23,3 +24,6 @@ export const md = markdownit({
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const API_BASE_PREFIX = dev ? "http://localhost:3000" : "/api";
|
||||||
|
export const NGINX_BASE_PREFIX = dev ? "http://localhost:18000" : "/user-websites";
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import type { Actions } from "./$types";
|
import type { Actions } from "./$types";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const actions: Actions = {
|
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(`/api/rpc/login`, {
|
const res = await fetch(`${API_BASE_PREFIX}/rpc/login`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import type { Actions } from "./$types";
|
import type { Actions } from "./$types";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const actions: Actions = {
|
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(`/api/rpc/register`, {
|
const res = await fetch(`${API_BASE_PREFIX}/rpc/register`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { Actions, PageServerLoad } from "./$types";
|
import type { Actions, PageServerLoad } from "./$types";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ fetch, cookies, url }) => {
|
export const load: PageServerLoad = async ({ fetch, cookies, url }) => {
|
||||||
const searchQuery = url.searchParams.get("website_search_query");
|
const searchQuery = url.searchParams.get("website_search_query");
|
||||||
@@ -6,7 +7,7 @@ export const load: PageServerLoad = async ({ fetch, cookies, url }) => {
|
|||||||
|
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
const baseFetchUrl = `/api/website`;
|
const baseFetchUrl = `${API_BASE_PREFIX}/website`;
|
||||||
|
|
||||||
if (searchQuery) {
|
if (searchQuery) {
|
||||||
params.append("title", `ilike.*${searchQuery}*`);
|
params.append("title", `ilike.*${searchQuery}*`);
|
||||||
@@ -63,7 +64,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(`/api/rpc/create_website`, {
|
const res = await fetch(`${API_BASE_PREFIX}/rpc/create_website`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -85,7 +86,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(`/api/website?id=eq.${data.get("id")}`, {
|
const res = await fetch(`${API_BASE_PREFIX}/website?id=eq.${data.get("id")}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -106,7 +107,7 @@ 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(`/api/website?id=eq.${data.get("id")}`, {
|
const res = await fetch(`${API_BASE_PREFIX}/website?id=eq.${data.get("id")}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { Actions, PageServerLoad } from "./$types";
|
import type { Actions, PageServerLoad } from "./$types";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ locals }) => {
|
export const load: PageServerLoad = async ({ locals }) => {
|
||||||
return {
|
return {
|
||||||
@@ -15,7 +16,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(`/api/rpc/delete_account`, {
|
const res = await fetch(`${API_BASE_PREFIX}/rpc/delete_account`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { LayoutServerLoad } from "./$types";
|
import type { LayoutServerLoad } from "./$types";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const load: LayoutServerLoad = async ({ params, fetch, cookies }) => {
|
export const load: LayoutServerLoad = async ({ params, fetch, cookies }) => {
|
||||||
const websiteData = await fetch(`/api/website?id=eq.${params.websiteId}`, {
|
const websiteData = await fetch(`${API_BASE_PREFIX}/website?id=eq.${params.websiteId}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -10,7 +11,7 @@ export const load: LayoutServerLoad = async ({ params, fetch, cookies }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const homeData = await fetch(`/api/home?website_id=eq.${params.websiteId}`, {
|
const homeData = await fetch(`${API_BASE_PREFIX}/home?website_id=eq.${params.websiteId}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -1,7 +1,20 @@
|
|||||||
import type { Actions, PageServerLoad } from "./$types";
|
import type { Actions, PageServerLoad } from "./$types";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
|
export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
|
||||||
const globalSettingsData = await fetch(`/api/settings?website_id=eq.${params.websiteId}`, {
|
const globalSettingsData = await fetch(
|
||||||
|
`${API_BASE_PREFIX}/settings?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(`${API_BASE_PREFIX}/header?website_id=eq.${params.websiteId}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -10,16 +23,7 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const headerData = await fetch(`/api/header?website_id=eq.${params.websiteId}`, {
|
const footerData = await fetch(`${API_BASE_PREFIX}/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(`/api/footer?website_id=eq.${params.websiteId}`, {
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -44,7 +48,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(`/api/rpc/upload_file`, {
|
const uploadedImageData = await fetch(`${API_BASE_PREFIX}/rpc/upload_file`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
@@ -63,7 +67,7 @@ export const actions: Actions = {
|
|||||||
return { success: false, message: uploadedImage.message };
|
return { success: false, message: uploadedImage.message };
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(`/api/settings?website_id=eq.${params.websiteId}`, {
|
const res = await fetch(`${API_BASE_PREFIX}/settings?website_id=eq.${params.websiteId}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -90,7 +94,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(`/api/rpc/upload_file`, {
|
const uploadedImageData = await fetch(`${API_BASE_PREFIX}/rpc/upload_file`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
@@ -109,7 +113,7 @@ export const actions: Actions = {
|
|||||||
return { success: false, message: uploadedImage.message };
|
return { success: false, message: uploadedImage.message };
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(`/api/header?website_id=eq.${params.websiteId}`, {
|
const res = await fetch(`${API_BASE_PREFIX}/header?website_id=eq.${params.websiteId}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -135,7 +139,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(`/api/home?website_id=eq.${params.websiteId}`, {
|
const res = await fetch(`${API_BASE_PREFIX}/home?website_id=eq.${params.websiteId}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -156,7 +160,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(`/api/footer?website_id=eq.${params.websiteId}`, {
|
const res = await fetch(`${API_BASE_PREFIX}/footer?website_id=eq.${params.websiteId}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
|
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
|
||||||
import type { ActionData, PageServerData } from "./$types";
|
import type { ActionData, PageServerData } from "./$types";
|
||||||
import Modal from "$lib/components/Modal.svelte";
|
import Modal from "$lib/components/Modal.svelte";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
const { data, form } = $props<{ data: PageServerData; form: ActionData }>();
|
const { data, form } = $props<{ data: PageServerData; form: ActionData }>();
|
||||||
</script>
|
</script>
|
||||||
@@ -55,7 +56,10 @@
|
|||||||
</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 src={`/api/rpc/retrieve_file?id=${data.globalSettings.favicon_image}`} alt="" />
|
<img
|
||||||
|
src={`${API_BASE_PREFIX}/rpc/retrieve_file?id=${data.globalSettings.favicon_image}`}
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -106,7 +110,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 src={`/api/rpc/retrieve_file?id=${data.header.logo_image}`} alt="" />
|
<img src={`${API_BASE_PREFIX}/rpc/retrieve_file?id=${data.header.logo_image}`} alt="" />
|
||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { Actions, PageServerLoad } from "./$types";
|
import type { Actions, PageServerLoad } from "./$types";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent }) => {
|
export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent }) => {
|
||||||
const searchQuery = url.searchParams.get("article_search_query");
|
const searchQuery = url.searchParams.get("article_search_query");
|
||||||
@@ -6,7 +7,7 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent
|
|||||||
|
|
||||||
const parameters = new URLSearchParams();
|
const parameters = new URLSearchParams();
|
||||||
|
|
||||||
const baseFetchUrl = `/api/article?website_id=eq.${params.websiteId}&select=id,title`;
|
const baseFetchUrl = `${API_BASE_PREFIX}/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 +67,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(`/api/article`, {
|
const res = await fetch(`${API_BASE_PREFIX}/article`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -89,7 +90,7 @@ 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(`/api/article?id=eq.${data.get("id")}`, {
|
const res = await fetch(`${API_BASE_PREFIX}/article?id=eq.${data.get("id")}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { Actions, PageServerLoad } from "./$types";
|
import type { Actions, PageServerLoad } from "./$types";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) => {
|
export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) => {
|
||||||
const articleData = await fetch(`/api/article?id=eq.${params.articleId}`, {
|
const articleData = await fetch(`${API_BASE_PREFIX}/article?id=eq.${params.articleId}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -21,7 +22,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(`/api/rpc/upload_file`, {
|
const uploadedImageData = await fetch(`${API_BASE_PREFIX}/rpc/upload_file`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
@@ -40,7 +41,7 @@ export const actions: Actions = {
|
|||||||
return { success: false, message: uploadedImage.message };
|
return { success: false, message: uploadedImage.message };
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(`/api/article?id=eq.${params.articleId}`, {
|
const res = await fetch(`${API_BASE_PREFIX}/article?id=eq.${params.articleId}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
|
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
|
||||||
import type { ActionData, PageServerData } from "./$types";
|
import type { ActionData, PageServerData } from "./$types";
|
||||||
import Modal from "$lib/components/Modal.svelte";
|
import Modal from "$lib/components/Modal.svelte";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
const { data, form } = $props<{ data: PageServerData; form: ActionData }>();
|
const { data, form } = $props<{ data: PageServerData; form: ActionData }>();
|
||||||
</script>
|
</script>
|
||||||
@@ -68,7 +69,10 @@
|
|||||||
</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 src={`/api/rpc/retrieve_file?id=${data.article.cover_image}`} alt="" />
|
<img
|
||||||
|
src={`${API_BASE_PREFIX}/rpc/retrieve_file?id=${data.article.cover_image}`}
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import type { Actions, PageServerLoad } from "./$types";
|
import type { Actions, PageServerLoad } from "./$types";
|
||||||
|
import { API_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ parent, params, fetch, cookies }) => {
|
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(
|
||||||
`/api/collab?website_id=eq.${params.websiteId}&select=*,user!user_id(*)`,
|
`${API_BASE_PREFIX}/collab?website_id=eq.${params.websiteId}&select=*,user!user_id(*)`,
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -27,7 +28,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(`/api/collab`, {
|
const res = await fetch(`${API_BASE_PREFIX}/collab`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -51,7 +52,7 @@ export const actions: Actions = {
|
|||||||
const data = await request.formData();
|
const data = await request.formData();
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`/api/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`,
|
`${API_BASE_PREFIX}/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`,
|
||||||
{
|
{
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -75,7 +76,7 @@ export const actions: Actions = {
|
|||||||
const data = await request.formData();
|
const data = await request.formData();
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`/api/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`,
|
`${API_BASE_PREFIX}/collab?website_id=eq.${params.websiteId}&user_id=eq.${data.get("user-id")}`,
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -2,22 +2,26 @@ import { readFile, mkdir, writeFile } from "node:fs/promises";
|
|||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { md } from "$lib/utils";
|
import { md } from "$lib/utils";
|
||||||
import type { Actions, PageServerLoad } from "./$types";
|
import type { Actions, PageServerLoad } from "./$types";
|
||||||
|
import { API_BASE_PREFIX, NGINX_BASE_PREFIX } from "$lib/utils";
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, fetch, cookies, locals }) => {
|
export const load: PageServerLoad = async ({ params, fetch, cookies, locals }) => {
|
||||||
const websiteOverviewData = await fetch(`/api/website_overview?id=eq.${params.websiteId}`, {
|
const websiteOverviewData = await fetch(
|
||||||
method: "GET",
|
`${API_BASE_PREFIX}/website_overview?id=eq.${params.websiteId}`,
|
||||||
headers: {
|
{
|
||||||
"Content-Type": "application/json",
|
method: "GET",
|
||||||
Authorization: `Bearer ${cookies.get("session_token")}`,
|
headers: {
|
||||||
Accept: "application/vnd.pgrst.object+json"
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${cookies.get("session_token")}`,
|
||||||
|
Accept: "application/vnd.pgrst.object+json"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
const websiteOverview = await websiteOverviewData.json();
|
const websiteOverview = await websiteOverviewData.json();
|
||||||
|
|
||||||
generateStaticFiles(websiteOverview);
|
generateStaticFiles(websiteOverview);
|
||||||
|
|
||||||
const websitePreviewUrl = `/user-websites/previews/${websiteOverview.user_id}/${websiteOverview.id}/index.html`;
|
const websitePreviewUrl = `${NGINX_BASE_PREFIX}/previews/${websiteOverview.user_id}/${websiteOverview.id}/index.html`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
websiteOverview,
|
websiteOverview,
|
||||||
@@ -122,7 +126,7 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
|||||||
)
|
)
|
||||||
.replace(
|
.replace(
|
||||||
"{{cover_image}}",
|
"{{cover_image}}",
|
||||||
`<img src="${article.cover_image ? `/api/rpc/retrieve_file?id=${article.cover_image}` : "https://picsum.photos/600/200"}" />`
|
`<img src="${article.cover_image ? `${API_BASE_PREFIX}/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>`)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { page } from "$app/stores";
|
import { page } from "$app/stores";
|
||||||
import type { LayoutServerData } from "./$types";
|
import type { LayoutServerData } from "./$types";
|
||||||
import type { Snippet } from "svelte";
|
import type { Snippet } from "svelte";
|
||||||
|
import { dev } from "$app/environment";
|
||||||
|
|
||||||
const { data, children } = $props<{ data: LayoutServerData; children: Snippet }>();
|
const { data, children } = $props<{ data: LayoutServerData; children: Snippet }>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user