Create nix derivations for building and running web app

This commit is contained in:
thiloho
2024-08-09 16:17:33 +02:00
parent 2fd934ed86
commit 99645ec874
7 changed files with 105 additions and 29 deletions

View File

@@ -42,6 +42,8 @@
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
in in
{ {
dev-vm = self.nixosConfigurations.${system}.dev-vm.config.system.build.vm;
api-setup = pkgs.writeShellScriptBin "api-setup" '' api-setup = pkgs.writeShellScriptBin "api-setup" ''
source .env source .env
@@ -53,7 +55,38 @@
PGRST_DB_URI="$PGRST_DB_URI" PGRST_JWT_SECRET="$JWT_SECRET" ${pkgs.postgrest}/bin/postgrest postgrest.conf PGRST_DB_URI="$PGRST_DB_URI" PGRST_JWT_SECRET="$JWT_SECRET" ${pkgs.postgrest}/bin/postgrest postgrest.conf
''; '';
dev-vm = self.nixosConfigurations.${system}.dev-vm.config.system.build.vm;
web = pkgs.buildNpmPackage {
name = "archtika-web-app";
src = ./web-app;
npmDepsHash = "sha256-DmIII/x5ANlEpKtnZC/JlbVAvhbgnSiNn8hkj+qVCZY=";
npmFlags = [ "--legacy-peer-deps" ];
installPhase = ''
mkdir $out
cp package.json $out
cp -r node_modules $out
cp -r build/* $out
'';
};
}
);
apps = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
web = {
type = "app";
program = "${pkgs.writeShellScriptBin "web-wrapper" ''
export ORIGIN=http://localhost:4000
export HOST=127.0.0.1
export PORT=4000
${pkgs.nodejs_22}/bin/node ${self.packages.${system}.web}
''}/bin/web-wrapper";
};
} }
); );

1
web-app/.gitignore vendored
View File

@@ -1,6 +1,7 @@
node_modules node_modules
user-uploads user-uploads
user-websites user-websites
result
# Output # Output
.output .output

View File

@@ -161,13 +161,20 @@ form[method="GET"] > button[type="submit"] {
align-self: end; align-self: end;
} }
form > label { form label {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 0.25rem; gap: 0.25rem;
max-inline-size: 30ch; max-inline-size: 30ch;
} }
form > label:has(textarea) { form label:has(textarea) {
max-inline-size: 65ch; max-inline-size: 65ch;
} }
form .file-field {
display: flex;
align-items: end;
gap: 0.5rem;
flex-wrap: wrap;
}

View File

@@ -4,6 +4,7 @@
import { ALLOWED_MIME_TYPES } from "$lib/utils"; import { ALLOWED_MIME_TYPES } from "$lib/utils";
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";
const { data, form } = $props<{ data: PageServerData; form: ActionData }>(); const { data, form } = $props<{ data: PageServerData; form: ActionData }>();
</script> </script>
@@ -47,10 +48,20 @@
required required
/> />
</label> </label>
<div class="file-field">
<label> <label>
Favicon: Favicon:
<input type="file" name="favicon" accept={ALLOWED_MIME_TYPES.join(", ")} /> <input type="file" name="favicon" accept={ALLOWED_MIME_TYPES.join(", ")} />
</label> </label>
{#if data.globalSettings.media}
<Modal id="preview-favicon-global-{data.globalSettings.website_id}" text="Preview">
<img
src={`http://localhost:5173/${data.globalSettings.media.file_system_path}`}
alt={data.globalSettings.media.original_name}
/>
</Modal>
{/if}
</div>
<button type="submit">Submit</button> <button type="submit">Submit</button>
</form> </form>
@@ -86,6 +97,7 @@
required={data.header.logo_type === "text"} required={data.header.logo_type === "text"}
/> />
</label> </label>
<div class="file-field">
<label> <label>
Logo image: Logo image:
<input <input
@@ -95,6 +107,15 @@
required={data.header.logo_type === "image"} required={data.header.logo_type === "image"}
/> />
</label> </label>
{#if data.header.media}
<Modal id="preview-logo-header-{data.header.website_id}" text="Preview">
<img
src={`http://localhost:5173/${data.header.media.file_system_path}`}
alt={data.header.media.original_name}
/>
</Modal>
{/if}
</div>
<button type="submit">Submit</button> <button type="submit">Submit</button>
</form> </form>

View File

@@ -2,14 +2,17 @@ import { handleFileUpload } from "$lib/server/utils.js";
import type { Actions, PageServerLoad } from "./$types"; import type { Actions, PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) => { export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) => {
const articleData = await fetch(`http://localhost:3000/article?id=eq.${params.articleId}`, { const articleData = await fetch(
`http://localhost:3000/article?id=eq.${params.articleId}&select=*,media(*)`,
{
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`, Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json" Accept: "application/vnd.pgrst.object+json"
} }
}); }
);
const article = await articleData.json(); const article = await articleData.json();
const { website } = await parent(); const { website } = await parent();

View File

@@ -4,6 +4,7 @@
import { ALLOWED_MIME_TYPES } from "$lib/utils"; import { ALLOWED_MIME_TYPES } from "$lib/utils";
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";
const { data, form } = $props<{ data: PageServerData; form: ActionData }>(); const { data, form } = $props<{ data: PageServerData; form: ActionData }>();
</script> </script>
@@ -60,10 +61,20 @@
Publication date: Publication date:
<input type="date" name="publication-date" value={data.article.publication_date} required /> <input type="date" name="publication-date" value={data.article.publication_date} required />
</label> </label>
<div class="file-field">
<label> <label>
Cover image: Cover image:
<input type="file" name="cover-image" accept={ALLOWED_MIME_TYPES.join(", ")} /> <input type="file" name="cover-image" accept={ALLOWED_MIME_TYPES.join(", ")} />
</label> </label>
{#if data.article.media}
<Modal id="preview-cover-article-{data.article.id}" text="Preview">
<img
src={`http://localhost:5173/${data.article.media.file_system_path}`}
alt={data.article.media.original_name}
/>
</Modal>
{/if}
</div>
<label> <label>
Main content: Main content:
<textarea name="main-content" rows="20" required>{data.article.main_content}</textarea> <textarea name="main-content" rows="20" required>{data.article.main_content}</textarea>

View File

@@ -1,8 +1,8 @@
import adapter from "@sveltejs/adapter-node"; import adapter from "@sveltejs/adapter-node";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import { Config } from "@sveltejs/kit";
const config: Config = { /** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors // Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors // for more information about preprocessors
preprocess: vitePreprocess(), preprocess: vitePreprocess(),