Skip to content

Commit

Permalink
feat: docker with static deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
httpjamesm committed Dec 10, 2023
1 parent 9539479 commit 4489623
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

docker-compose.yml
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:18-alpine AS builder
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build

# Serve static
FROM nginx:stable-alpine
COPY --from=builder /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
11 changes: 11 additions & 0 deletions docker-compose.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.8'

services:
frontend:
container_name: carbon-paper-app
build:
context: .
dockerfile: Dockerfile
ports:
- 80
env_file: .env
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.20.4",
"@types/libsodium-wrappers-sumo": "^0.7.8",
"@types/qrcode": "^1.5.5",
Expand Down
2 changes: 2 additions & 0 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ssr = false;
export const prerender = true;
10 changes: 6 additions & 4 deletions src/routes/v/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import { page } from '$app/stores';
import { PUBLIC_API_URL } from '$env/static/public';
import PasteViewer from './PasteViewer.svelte';
import type { PasteRequestBody } from '$lib/types/pasteCreation';
Expand All @@ -11,7 +10,6 @@
import Alert from '$lib/components/Alert.svelte';
import Logo from '$lib/components/Logo.svelte';
const pasteId = $page.url.searchParams.get('id');
let password = '';
let requestPassword = false;
Expand All @@ -30,10 +28,12 @@
let errorMessage = '';
const getPasteMetadata = async () => {
const searchParams = new URLSearchParams(window.location.search);
let res: Response;
try {
res = await fetch(`${PUBLIC_API_URL}/metadata/${pasteId}`);
res = await fetch(`${PUBLIC_API_URL}/metadata/${searchParams.get('id')}`);
} catch (err) {
throw err;
}
Expand All @@ -54,7 +54,9 @@
};
const getPasteData = async (kekHash?: string) => {
let url = `${PUBLIC_API_URL}/data/${pasteId}`;
const searchParams = new URLSearchParams(window.location.search);
let url = `${PUBLIC_API_URL}/data/${searchParams.get('id')}`;
if (kekHash) {
url += `?passwordHash=${kekHash}`;
Expand Down
2 changes: 1 addition & 1 deletion svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adapter from '@sveltejs/adapter-auto';
import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/kit/vite';

/** @type {import('@sveltejs/kit').Config} */
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@
dependencies:
import-meta-resolve "^4.0.0"

"@sveltejs/adapter-static@^2.0.3":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@sveltejs/adapter-static/-/adapter-static-2.0.3.tgz#616836c30bdce4d673a2e26c0f5ffbd5c1bc7c67"
integrity sha512-VUqTfXsxYGugCpMqQv1U0LIdbR3S5nBkMMDmpjGVJyM6Q2jHVMFtdWJCkeHMySc6mZxJ+0eZK3T7IgmUCDrcUQ==

"@sveltejs/kit@^1.20.4":
version "1.27.5"
resolved "https://registry.yarnpkg.com/@sveltejs/kit/-/kit-1.27.5.tgz#df0521cb4f4f8c2cad612ee2587a4dc4f4fcdb7c"
Expand Down

0 comments on commit 4489623

Please sign in to comment.