diff --git a/.dockerignore b/.dockerignore index 343f41f..265ec9f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,13 +1,17 @@ +**/.git* + target -.env +**/*.db* + +**/.env + Dockerfile -.gitignore -*.db -*.db.wal -.git* .dockerignore + LICENSE -node_modules -.svelte-kit README.md -build \ No newline at end of file + +frontend/node_modules +.svelte-kit +build +frontend/pnpm-lock.yaml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 18b97c3..ed59b98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,11 @@ FROM rust:1 as rust-builder WORKDIR /app -COPY Cargo.toml Cargo.lock bot database ./ +COPY Cargo.toml Cargo.lock ./ +COPY bot /app/bot +COPY database /app/database -RUN cargo build --release +RUN cargo build -r --workspace # ******************************** # * Deploy the bot * @@ -46,13 +48,8 @@ WORKDIR /app COPY frontend/ ./ -ENV PNPM_HOME="/pnpm" -ENV PATH="$PNPM_HOME:$PATH" - -RUN corepack enable - -RUN pnpm install --prod --frozen-lockfile -RUN pnpm build +RUN npm install +RUN npm run build FROM node:18-alpine3.18 as web @@ -60,7 +57,7 @@ WORKDIR /app COPY --from=web-builder /app/build ./build COPY --from=web-builder /app/node_modules ./node_modules -COPY --from=web-builder /app/package.json /app/pnpm-lock.yaml ./ +COPY --from=web-builder /app/package.json /app/package-lock.json ./ ENV DOTENV_CONFIG_PATH=/app/config/.env diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index 5c91169..0000000 --- a/frontend/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# create-svelte - -Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). - -## Creating a project - -If you're seeing this, you've probably already done this step. Congrats! - -```bash -# create a new project in the current directory -npm create svelte@latest - -# create a new project in my-app -npm create svelte@latest my-app -``` - -## Developing - -Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: - -```bash -npm run dev - -# or start the server and open the app in a new browser tab -npm run dev -- --open -``` - -## Building - -To create a production version of your app: - -```bash -npm run build -``` - -You can preview the production build with `npm run preview`. - -> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. diff --git a/frontend/src/hooks.server.ts b/frontend/src/hooks.server.ts index b497a3e..3d4c4c9 100644 --- a/frontend/src/hooks.server.ts +++ b/frontend/src/hooks.server.ts @@ -1,4 +1,4 @@ -import { CLIENT_ID, CLIENT_SECRET, ORIGIN } from '$env/static/private'; +import { env } from '$env/dynamic/private'; import type { OAuth2Response } from '$lib/types'; import { redirect, type Handle } from '@sveltejs/kit'; import { sequence } from '@sveltejs/kit/hooks'; @@ -16,15 +16,15 @@ const auth: Handle = async ({ resolve, event }) => { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ - client_id: CLIENT_ID, - client_secret: CLIENT_SECRET, + client_id: env.CLIENT_ID, + client_secret: env.CLIENT_SECRET, grant_type: 'refresh_token', refresh_token: refreshToken }) }); if (!rsp.ok) { - console.log(`failed to refresh token: ${rsp.status}`); + console.error(`failed to refresh token: ${rsp.status}`); event.cookies.delete('refresh-token'); throw redirect(303, '/login'); } @@ -41,7 +41,6 @@ const auth: Handle = async ({ resolve, event }) => { // * grab the access token again, in case it was just refreshed event.locals.session = !!(event.cookies.get('access-token') && refreshToken); - console.log(`session: ${event.locals.session}`); return await resolve(event); }; @@ -55,8 +54,8 @@ const handleAuth: Handle = async ({ resolve, event }) => { throw redirect(303, '/login'); } else if (event.locals.session) return await resolve(event); - if (event.url.origin !== ORIGIN) { - console.log(`invalid origin: ${event.url.origin}`); + if (event.url.origin !== env.ORIGIN) { + console.error(`invalid origin: ${event.url.origin}`); throw redirect(303, '/login'); } @@ -68,7 +67,7 @@ const handleAuth: Handle = async ({ resolve, event }) => { else if (event.url.pathname === '/auth/callback/discord') { const code = event.url.searchParams.get('code'); if (!code) { - console.log(`failed to get code in callback url: ${event.url}`); + console.error(`failed to get code in callback url: ${event.url}`); throw redirect(303, '/login'); } @@ -78,10 +77,10 @@ const handleAuth: Handle = async ({ resolve, event }) => { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ - client_id: CLIENT_ID, - client_secret: CLIENT_SECRET, + client_id: env.CLIENT_ID, + client_secret: env.CLIENT_SECRET, grant_type: 'authorization_code', - redirect_uri: `${ORIGIN}/auth/callback/discord`, + redirect_uri: `${env.ORIGIN}/auth/callback/discord`, code }) }); @@ -104,7 +103,7 @@ const handleAuth: Handle = async ({ resolve, event }) => { path: '/' }); - console.log('successfully authenticated user'); + console.info('successfully authenticated user'); throw redirect(303, '/'); } @@ -113,7 +112,7 @@ const handleAuth: Handle = async ({ resolve, event }) => { const guard: Handle = async ({ resolve, event }) => { if (protectedRoutes.includes(event.url.pathname) && !event.locals.session) { - console.log(`authentication failed for: ${event.url.pathname}`); + console.warn(`authentication failed for: ${event.url.pathname}`); throw redirect(303, '/login'); } else if (event.url.pathname === '/login' && event.locals.session) throw redirect(303, '/'); diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte index 14dfbc0..ba393e4 100644 --- a/frontend/src/routes/+layout.svelte +++ b/frontend/src/routes/+layout.svelte @@ -1,5 +1,5 @@