Skip to content

Commit

Permalink
Add sveltekit_app to Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinEtchells committed Nov 14, 2024
1 parent a7958b4 commit 09ae2e1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ services:
timeout: 30s
retries: 24
start_period: 60s
sveltekit-app:
image: sveltekit-app:latest
build:
context: .
dockerfile: ./sveltekit_app/Dockerfile
user: "node"
networks:
- redbox-app-network
ports:
- "3000:3000"
restart: unless-stopped
env_file:
- path: .env
required: false
db:
image: postgres:13
env_file:
Expand Down
15 changes: 15 additions & 0 deletions sveltekit_app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:20

WORKDIR /app

COPY sveltekit_app/package.json ./
RUN npm install

COPY sveltekit_app/ ./
RUN npm run build

USER node:node

EXPOSE 3000

CMD ["node", "build/index.js"]
19 changes: 13 additions & 6 deletions sveltekit_app/src/routes/+layout.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ export async function load({ request, cookies }) {

const API_URL = "http://localhost:8091/api/v0?format=json";

const userRequest = await fetch(API_URL, {
headers: {
cookie: `sessionid=${cookies.get("sessionid")}`,
},
});
const userData = userRequest.ok ? await userRequest.json() : {};
let userData = {};

try {
const userRequest = await fetch(API_URL, {
headers: {
cookie: `sessionid=${cookies.get("sessionid")}`,
},
});
userData = userRequest.ok ? await userRequest.json() : {};
} catch (err) {
console.log("Error connecting to Django", err);
}


const publicRoutes = [
"/",
Expand Down
6 changes: 2 additions & 4 deletions sveltekit_app/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import adapter from '@sveltejs/adapter-auto';
//import adapter from '@sveltejs/adapter-auto';
import adapter from '@sveltejs/adapter-node';

/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter()
}
};
Expand Down

0 comments on commit 09ae2e1

Please sign in to comment.