use dynamic env frontend & update dockerfile
This commit is contained in:
parent
20ff50e5af
commit
dc84416985
|
@ -1,13 +1,17 @@
|
||||||
|
**/.git*
|
||||||
|
|
||||||
target
|
target
|
||||||
.env
|
**/*.db*
|
||||||
|
|
||||||
|
**/.env
|
||||||
|
|
||||||
Dockerfile
|
Dockerfile
|
||||||
.gitignore
|
|
||||||
*.db
|
|
||||||
*.db.wal
|
|
||||||
.git*
|
|
||||||
.dockerignore
|
.dockerignore
|
||||||
|
|
||||||
LICENSE
|
LICENSE
|
||||||
node_modules
|
|
||||||
.svelte-kit
|
|
||||||
README.md
|
README.md
|
||||||
build
|
|
||||||
|
frontend/node_modules
|
||||||
|
.svelte-kit
|
||||||
|
build
|
||||||
|
frontend/pnpm-lock.yaml
|
17
Dockerfile
17
Dockerfile
|
@ -6,9 +6,11 @@ FROM rust:1 as rust-builder
|
||||||
|
|
||||||
WORKDIR /app
|
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 *
|
# * Deploy the bot *
|
||||||
|
@ -46,13 +48,8 @@ WORKDIR /app
|
||||||
|
|
||||||
COPY frontend/ ./
|
COPY frontend/ ./
|
||||||
|
|
||||||
ENV PNPM_HOME="/pnpm"
|
RUN npm install
|
||||||
ENV PATH="$PNPM_HOME:$PATH"
|
RUN npm run build
|
||||||
|
|
||||||
RUN corepack enable
|
|
||||||
|
|
||||||
RUN pnpm install --prod --frozen-lockfile
|
|
||||||
RUN pnpm build
|
|
||||||
|
|
||||||
FROM node:18-alpine3.18 as web
|
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/build ./build
|
||||||
COPY --from=web-builder /app/node_modules ./node_modules
|
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
|
ENV DOTENV_CONFIG_PATH=/app/config/.env
|
||||||
|
|
||||||
|
|
|
@ -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.
|
|
|
@ -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 type { OAuth2Response } from '$lib/types';
|
||||||
import { redirect, type Handle } from '@sveltejs/kit';
|
import { redirect, type Handle } from '@sveltejs/kit';
|
||||||
import { sequence } from '@sveltejs/kit/hooks';
|
import { sequence } from '@sveltejs/kit/hooks';
|
||||||
|
@ -16,15 +16,15 @@ const auth: Handle = async ({ resolve, event }) => {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
},
|
},
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
client_id: CLIENT_ID,
|
client_id: env.CLIENT_ID,
|
||||||
client_secret: CLIENT_SECRET,
|
client_secret: env.CLIENT_SECRET,
|
||||||
grant_type: 'refresh_token',
|
grant_type: 'refresh_token',
|
||||||
refresh_token: refreshToken
|
refresh_token: refreshToken
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!rsp.ok) {
|
if (!rsp.ok) {
|
||||||
console.log(`failed to refresh token: ${rsp.status}`);
|
console.error(`failed to refresh token: ${rsp.status}`);
|
||||||
event.cookies.delete('refresh-token');
|
event.cookies.delete('refresh-token');
|
||||||
throw redirect(303, '/login');
|
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
|
// * grab the access token again, in case it was just refreshed
|
||||||
event.locals.session = !!(event.cookies.get('access-token') && refreshToken);
|
event.locals.session = !!(event.cookies.get('access-token') && refreshToken);
|
||||||
console.log(`session: ${event.locals.session}`);
|
|
||||||
|
|
||||||
return await resolve(event);
|
return await resolve(event);
|
||||||
};
|
};
|
||||||
|
@ -55,8 +54,8 @@ const handleAuth: Handle = async ({ resolve, event }) => {
|
||||||
throw redirect(303, '/login');
|
throw redirect(303, '/login');
|
||||||
} else if (event.locals.session) return await resolve(event);
|
} else if (event.locals.session) return await resolve(event);
|
||||||
|
|
||||||
if (event.url.origin !== ORIGIN) {
|
if (event.url.origin !== env.ORIGIN) {
|
||||||
console.log(`invalid origin: ${event.url.origin}`);
|
console.error(`invalid origin: ${event.url.origin}`);
|
||||||
throw redirect(303, '/login');
|
throw redirect(303, '/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +67,7 @@ const handleAuth: Handle = async ({ resolve, event }) => {
|
||||||
else if (event.url.pathname === '/auth/callback/discord') {
|
else if (event.url.pathname === '/auth/callback/discord') {
|
||||||
const code = event.url.searchParams.get('code');
|
const code = event.url.searchParams.get('code');
|
||||||
if (!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');
|
throw redirect(303, '/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,10 +77,10 @@ const handleAuth: Handle = async ({ resolve, event }) => {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
},
|
},
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
client_id: CLIENT_ID,
|
client_id: env.CLIENT_ID,
|
||||||
client_secret: CLIENT_SECRET,
|
client_secret: env.CLIENT_SECRET,
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
redirect_uri: `${ORIGIN}/auth/callback/discord`,
|
redirect_uri: `${env.ORIGIN}/auth/callback/discord`,
|
||||||
code
|
code
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -104,7 +103,7 @@ const handleAuth: Handle = async ({ resolve, event }) => {
|
||||||
path: '/'
|
path: '/'
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('successfully authenticated user');
|
console.info('successfully authenticated user');
|
||||||
throw redirect(303, '/');
|
throw redirect(303, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +112,7 @@ const handleAuth: Handle = async ({ resolve, event }) => {
|
||||||
|
|
||||||
const guard: Handle = async ({ resolve, event }) => {
|
const guard: Handle = async ({ resolve, event }) => {
|
||||||
if (protectedRoutes.includes(event.url.pathname) && !event.locals.session) {
|
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');
|
throw redirect(303, '/login');
|
||||||
} else if (event.url.pathname === '/login' && event.locals.session) throw redirect(303, '/');
|
} else if (event.url.pathname === '/login' && event.locals.session) throw redirect(303, '/');
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { PUBLIC_GRAPHQL_ENDPOINT } from '$env/static/public';
|
import { env } from '$env/dynamic/public';
|
||||||
import Toast from '$lib/components/toast.svelte';
|
import Toast from '$lib/components/toast.svelte';
|
||||||
import Icon from '@iconify/svelte';
|
import Icon from '@iconify/svelte';
|
||||||
import { Client, cacheExchange, fetchExchange, setContextClient } from '@urql/svelte';
|
import { Client, cacheExchange, fetchExchange, setContextClient } from '@urql/svelte';
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
setContextClient(
|
setContextClient(
|
||||||
new Client({
|
new Client({
|
||||||
url: PUBLIC_GRAPHQL_ENDPOINT,
|
url: env.PUBLIC_GRAPHQL_ENDPOINT,
|
||||||
exchanges: [cacheExchange, fetchExchange]
|
exchanges: [cacheExchange, fetchExchange]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -26,7 +26,10 @@
|
||||||
<div class="flex-1 justify-end space-x-5 mr-5">
|
<div class="flex-1 justify-end space-x-5 mr-5">
|
||||||
{#if data.id && data.avatar && data.username}
|
{#if data.id && data.avatar && data.username}
|
||||||
<div class="tooltip tooltip-bottom tooltip-info" data-tip="Copy ID">
|
<div class="tooltip tooltip-bottom tooltip-info" data-tip="Copy ID">
|
||||||
<button class="btn btn-ghost p-0 normal-case" on:click={() => navigator.clipboard.writeText(data.id)}>
|
<button
|
||||||
|
class="btn btn-ghost p-0 normal-case"
|
||||||
|
on:click={() => navigator.clipboard.writeText(data.id)}
|
||||||
|
>
|
||||||
{data.username}
|
{data.username}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue