working docker compose
This commit is contained in:
@@ -27,7 +27,7 @@ services:
|
|||||||
- sqlite:/database/
|
- sqlite:/database/
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=file:/database/db.sqlite
|
- DATABASE_URL=file:/database/db.sqlite
|
||||||
- FRONTEND_URL=http://0.0.0.0:3000
|
- FRONTEND_URL=http://localhost:3000
|
||||||
depends_on:
|
depends_on:
|
||||||
- migrate
|
- migrate
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -9,7 +9,7 @@ RUN npm ci
|
|||||||
# Copy all local files into the image.
|
# Copy all local files into the image.
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
ENV VITE_BACKEND_URL="http://0.0.0.0:8080"
|
ENV VITE_SERVER_INTERNAL="http://server:8080"
|
||||||
ENV VITE_BRANDING="Noteshare.space"
|
ENV VITE_BRANDING="Noteshare.space"
|
||||||
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
@@ -20,8 +20,7 @@ RUN npm prune --production
|
|||||||
FROM node:16-alpine
|
FROM node:16-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=0 /app .
|
COPY --from=BUILD_IMAGE /app .
|
||||||
COPY . .
|
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["node", "./build"]
|
CMD ["node", "./build"]
|
||||||
@@ -1,48 +1,57 @@
|
|||||||
<script context="module" , lang="ts">
|
<script context="module" , lang="ts">
|
||||||
import type { Load } from '@sveltejs/kit';
|
import type { Load } from '@sveltejs/kit';
|
||||||
import type { EncryptedNote } from '$lib/model/EncryptedNote';
|
|
||||||
|
|
||||||
export const load: Load = async ({ params, fetch, session, stuff }) => {
|
export const load: Load = async ({ props }) => {
|
||||||
const url = `${import.meta.env.VITE_BACKEND_URL}/note/${params.id}`;
|
const note: EncryptedNote = props.note;
|
||||||
const response = await fetch(url);
|
const maxage = Math.floor((note.expire_time.valueOf() - note.insert_time.valueOf()) / 1000);
|
||||||
|
return {
|
||||||
|
status: 200,
|
||||||
|
cache: {
|
||||||
|
maxage: maxage,
|
||||||
|
private: false
|
||||||
|
},
|
||||||
|
props: { note }
|
||||||
|
};
|
||||||
|
|
||||||
if (response.ok) {
|
// if (response.ok) {
|
||||||
try {
|
// try {
|
||||||
const note: EncryptedNote = await response.json();
|
// const note: EncryptedNote = await response.json();
|
||||||
note.insert_time = new Date(note.insert_time as unknown as string);
|
// note.insert_time = new Date(note.insert_time as unknown as string);
|
||||||
note.expire_time = new Date(note.expire_time as unknown as string);
|
// note.expire_time = new Date(note.expire_time as unknown as string);
|
||||||
const maxage = Math.floor((note.expire_time.valueOf() - note.insert_time.valueOf()) / 1000);
|
// const maxage = Math.floor((note.expire_time.valueOf() - note.insert_time.valueOf()) / 1000);
|
||||||
return {
|
// return {
|
||||||
status: response.status,
|
// status: response.status,
|
||||||
cache: {
|
// cache: {
|
||||||
maxage: maxage,
|
// maxage: maxage,
|
||||||
private: false
|
// private: false
|
||||||
},
|
// },
|
||||||
props: { note }
|
// props: { note }
|
||||||
};
|
// };
|
||||||
} catch {
|
// } catch {
|
||||||
return {
|
// return {
|
||||||
status: 500,
|
// status: 500,
|
||||||
error: response.statusText
|
// error: response.statusText
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
return {
|
// return {
|
||||||
status: response.status,
|
// status: response.status,
|
||||||
error: response.statusText
|
// error: response.statusText
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { browser } from '$app/env';
|
|
||||||
import decrypt from '$lib/crypto/decrypt';
|
import decrypt from '$lib/crypto/decrypt';
|
||||||
import MarkdownRenderer from '$lib/components/MarkdownRenderer.svelte';
|
import MarkdownRenderer from '$lib/components/MarkdownRenderer.svelte';
|
||||||
import LogoMarkdown from 'svelte-icons/io/IoLogoMarkdown.svelte';
|
import LogoMarkdown from 'svelte-icons/io/IoLogoMarkdown.svelte';
|
||||||
import IconEncrypted from 'svelte-icons/md/MdLockOutline.svelte';
|
import IconEncrypted from 'svelte-icons/md/MdLockOutline.svelte';
|
||||||
|
import type { EncryptedNote } from '$lib/model/EncryptedNote';
|
||||||
|
import { browser } from '$app/env';
|
||||||
|
|
||||||
|
// Auto-loaded from [id].ts endpoint
|
||||||
export let note: EncryptedNote;
|
export let note: EncryptedNote;
|
||||||
let plaintext: string;
|
let plaintext: string;
|
||||||
let timeString: string;
|
let timeString: string;
|
||||||
|
|||||||
37
webapp/src/routes/note/[id].ts
Normal file
37
webapp/src/routes/note/[id].ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import type { EncryptedNote } from '$lib/model/EncryptedNote';
|
||||||
|
import type { RequestHandler } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
export const get: RequestHandler = async ({ params }) => {
|
||||||
|
const url = `${import.meta.env.VITE_SERVER_INTERNAL}/note/${params.id}`;
|
||||||
|
const response = await fetch(url);
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
try {
|
||||||
|
const note: EncryptedNote = await response.json();
|
||||||
|
note.insert_time = new Date(note.insert_time as unknown as string);
|
||||||
|
note.expire_time = new Date(note.expire_time as unknown as string);
|
||||||
|
const maxage = Math.floor((note.expire_time.valueOf() - note.insert_time.valueOf()) / 1000);
|
||||||
|
return {
|
||||||
|
status: response.status,
|
||||||
|
headers: {
|
||||||
|
'Cache-Control': `public, max-age=${maxage}`
|
||||||
|
},
|
||||||
|
cache: {
|
||||||
|
maxage: maxage,
|
||||||
|
private: false
|
||||||
|
},
|
||||||
|
body: { note }
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
return {
|
||||||
|
status: 500,
|
||||||
|
error: response.statusText
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: response.status,
|
||||||
|
error: response.statusText
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user