From 03eb01d897b0bfe03ec9425096a41a82ad1be4e9 Mon Sep 17 00:00:00 2001
From: GDWR <57012020+GDWR@users.noreply.github.com>
Date: Thu, 20 Jun 2024 16:54:57 +0000
Subject: [PATCH] Path based routing and docker compose config update for local
dev
These changes do not work well on windows and the compose.yml file as well as env vars will need to be tweaked for local dev when deploying the website in docker versus using yarn dev
---
.env.sample | 3 ++-
compose.yml | 9 +++------
src/api/Dockerfile | 4 ++--
src/api/abandonauth/routers/ui.py | 2 +-
.../20240415115059_add_test_user/migration.sql | 3 ---
src/website/components/LoginButton.vue | 4 ----
src/website/layouts/dashboard.vue | 6 ++----
src/website/nuxt.config.ts | 9 ++++++---
src/website/pages/developer-applications/[id].vue | 9 ++++-----
src/website/pages/developer-applications/index.vue | 5 ++---
src/website/pages/index.vue | 3 +--
src/website/server/api/[...].ts | 8 ++++++++
12 files changed, 31 insertions(+), 34 deletions(-)
create mode 100644 src/website/server/api/[...].ts
diff --git a/.env.sample b/.env.sample
index a08d634..62f6e92 100644
--- a/.env.sample
+++ b/.env.sample
@@ -1,5 +1,5 @@
POSTGRES_DB=postgres
-POSTGRES_HOST=database
+POSTGRES_HOST=localhost
POSTGRES_PASSWORD=postgres
POSTGRES_USER=postgres
DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}"
@@ -9,6 +9,7 @@ JWT_HASHING_ALGO=HS512
JWT_EXPIRES_IN_SECONDS_LONG_LIVED=2592000
JWT_EXPIRES_IN_SECONDS_SHORT_LIVED=120
+ABANDON_AUTH_URL=http://localhost:8000
ABANDON_AUTH_SITE_URL=http://localhost:3000
ABANDON_AUTH_DISCORD_REDIRECT=
diff --git a/compose.yml b/compose.yml
index 96b50c9..92cb312 100644
--- a/compose.yml
+++ b/compose.yml
@@ -1,6 +1,7 @@
services:
abandonauth:
+ network_mode: "host"
build:
context: src/api
dockerfile: Dockerfile
@@ -10,13 +11,12 @@ services:
- ".env"
depends_on:
- database
- ports:
- - "8000:80"
volumes: # mount the source code as a volume, so we can use hot reloading
- "./src/api/abandonauth:/app/abandonauth:ro"
- "./prisma:/app/prisma:ro"
website:
+ network_mode: "host"
build:
context: ./src/website
dockerfile: Dockerfile
@@ -25,11 +25,10 @@ services:
ABANDON_AUTH_DEVELOPER_APP_ID: ${ABANDON_AUTH_DEVELOPER_APP_ID}
GITHUB_REDIRECT: ${GITHUB_REDIRECT}
DISCORD_REDIRECT: ${DISCORD_REDIRECT}
- ports:
- - "3000:3000"
database:
image: "postgres:${POSTGRES_VERSION:-15-alpine}"
+ network_mode: "host"
volumes:
- postgres_data:/var/lib/postgresql/data/
healthcheck:
@@ -37,8 +36,6 @@ services:
interval: 2s
timeout: 1s
retries: 5
- ports:
- - "127.0.0.1:5432:5432"
environment:
- "POSTGRES_HOST=${POSTGRES_HOST}"
- "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}"
diff --git a/src/api/Dockerfile b/src/api/Dockerfile
index 8a4834e..1bc9c3c 100644
--- a/src/api/Dockerfile
+++ b/src/api/Dockerfile
@@ -8,7 +8,7 @@ ADD ./abandonauth ./abandonauth
ADD ./prisma ./prisma
RUN poetry run prisma generate
-EXPOSE 80
+EXPOSE 8000
# Pull the uvicorn_extra build arg and ave it as an env var.
# The CMD instruction is ran at execution time, so it also needs to be an env var, so that it is available at that time.
@@ -16,4 +16,4 @@ ARG uvicorn_extras=""
ENV uvicorn_extras=$uvicorn_extras
ENTRYPOINT ["/bin/bash", "-c"]
-CMD ["poetry run uvicorn abandonauth:app --host 0.0.0.0 --port 80 $uvicorn_extras"]
+CMD ["poetry run uvicorn abandonauth:app --host 0.0.0.0 --port 8000 $uvicorn_extras"]
diff --git a/src/api/abandonauth/routers/ui.py b/src/api/abandonauth/routers/ui.py
index 21a2e32..752571f 100644
--- a/src/api/abandonauth/routers/ui.py
+++ b/src/api/abandonauth/routers/ui.py
@@ -13,7 +13,7 @@
router = APIRouter(prefix="/ui")
-BASE_URL = "http://localhost"
+BASE_URL = "http://localhost:8000"
COOKIE_DOMAIN_URL = "." + ".".join(urlparse(settings.ABANDON_AUTH_SITE_URL).netloc.split(".")[-2:])
diff --git a/src/api/prisma/migrations/20240415115059_add_test_user/migration.sql b/src/api/prisma/migrations/20240415115059_add_test_user/migration.sql
index 6ecbe37..b03e067 100644
--- a/src/api/prisma/migrations/20240415115059_add_test_user/migration.sql
+++ b/src/api/prisma/migrations/20240415115059_add_test_user/migration.sql
@@ -15,9 +15,6 @@ CREATE TABLE "TestUser" (
CONSTRAINT "TestUser_pkey" PRIMARY KEY ("id")
);
--- CreateIndex
-CREATE UNIQUE INDEX "CallbackUri_developer_application_id_uri_key" ON "CallbackUri"("developer_application_id", "uri");
-
-- CreateIndex
CREATE UNIQUE INDEX "User_id_username_key" ON "User"("id", "username");
diff --git a/src/website/components/LoginButton.vue b/src/website/components/LoginButton.vue
index 6effd2d..4ccd0b7 100644
--- a/src/website/components/LoginButton.vue
+++ b/src/website/components/LoginButton.vue
@@ -10,10 +10,6 @@
diff --git a/src/website/nuxt.config.ts b/src/website/nuxt.config.ts
index dcea473..4b4294f 100644
--- a/src/website/nuxt.config.ts
+++ b/src/website/nuxt.config.ts
@@ -1,14 +1,17 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
+ nitro: {
+ devProxy: {
+ '/api': process.env.ABANDON_AUTH_URL,
+ },
+ },
devtools: {
enabled: true,
-
timeline: {
enabled: true
}
},
css: ["/assets/css/main.css", "@fortawesome/fontawesome-svg-core/styles.css"],
-
modules: ["@nuxtjs/tailwindcss"],
tailwindcss: {
exposeConfig: true,
@@ -24,7 +27,7 @@ export default defineNuxtConfig({
abandonAuthApplicationId: process.env.ABANDON_AUTH_DEVELOPER_APP_ID,
githubRedirect: process.env.GITHUB_REDIRECT,
discordRedirect: process.env.DISCORD_REDIRECT,
- loginPath: `/login?application_id=${process.env.ABANDON_AUTH_DEVELOPER_APP_ID}&callback_uri=${process.env.ABANDON_AUTH_URL}/ui`
+ loginPath: `/login?application_id=${process.env.ABANDON_AUTH_DEVELOPER_APP_ID}&callback_uri=${process.env.ABANDON_AUTH_URL}/api/ui`
}
}
})
diff --git a/src/website/pages/developer-applications/[id].vue b/src/website/pages/developer-applications/[id].vue
index e34df64..68dba0a 100644
--- a/src/website/pages/developer-applications/[id].vue
+++ b/src/website/pages/developer-applications/[id].vue
@@ -81,7 +81,6 @@
import type { CreateDeveloperApplicationDto, DeveloperApplicationDto, DeveloperApplicationUpdateCallbackDto } from '~/types/developerApplicationDto';
import { faPlus, faTrash } from '@fortawesome/free-solid-svg-icons'
-const config = useRuntimeConfig()
const auth = useCookie("Authorization");
const route = useRoute()
const router = useRouter()
@@ -94,7 +93,7 @@ const showNewTokenModal = ref(false)
const application_id = route.params.id
-const { data: application, refresh } = await useFetch(`${config.public.abandonAuthUrl}/developer_application/${application_id}`, {
+const { data: application, refresh } = await useFetch(`/api/developer_application/${application_id}`, {
lazy: true,
headers: {
Authorization: `Bearer ${auth.value}`
@@ -111,7 +110,7 @@ async function resetCallbackUriField() {
async function submitNewCallbackUris(newUris: string[]) {
if (application.value?.callback_uris !== undefined){
- await $fetch(`${config.public.abandonAuthUrl}/developer_application/${application_id}/callback_uris`, {
+ await $fetch(`/api/developer_application/${application_id}/callback_uris`, {
method: "patch",
headers: {
Authorization: `Bearer ${auth.value}`
@@ -143,7 +142,7 @@ async function closeNewTokenModal() {
}
async function resetDeveloperApplicationToken() {
- let resp = await $fetch(`${config.public.abandonAuthUrl}/developer_application/${application_id}/reset_token`, {
+ let resp = await $fetch(`/api/developer_application/${application_id}/reset_token`, {
method: "patch",
headers: {
Authorization: `Bearer ${auth.value}`
@@ -163,7 +162,7 @@ async function resetDeveloperApplicationToken() {
}
async function deleteDeveloperApplication() {
- await $fetch(`${config.public.abandonAuthUrl}/developer_application/${application_id}`, {
+ await $fetch(`/api/developer_application/${application_id}`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${auth.value}`
diff --git a/src/website/pages/developer-applications/index.vue b/src/website/pages/developer-applications/index.vue
index 6096569..1aa5bcc 100644
--- a/src/website/pages/developer-applications/index.vue
+++ b/src/website/pages/developer-applications/index.vue
@@ -52,7 +52,6 @@
import { faPlus } from '@fortawesome/free-solid-svg-icons'
import type { CreateDeveloperApplicationDto, DeveloperApplicationDto } from '~/types/developerApplicationDto';
-const config = useRuntimeConfig()
const auth = useCookie("Authorization");
const spinAddButton = ref(false)
@@ -63,7 +62,7 @@ const createdApplicationId = ref("")
const createdApplicationName = ref("")
const createdApplicationToken = ref("")
-const { data: applications, refresh } = await useFetch(`${config.public.abandonAuthUrl}/user/applications`, {
+const { data: applications, refresh } = await useFetch('/api/user/applications', {
lazy: true,
headers: {
Authorization: `Bearer ${auth.value}`
@@ -97,7 +96,7 @@ async function createApplication(name: string) {
return resetApplicationField()
}
- const resp = await $fetch(`${config.public.abandonAuthUrl}/developer_application`, {
+ const resp = await $fetch('/api/developer_application', {
method: 'POST',
body: { name: name },
headers: {
diff --git a/src/website/pages/index.vue b/src/website/pages/index.vue
index 50a4a46..7449d10 100644
--- a/src/website/pages/index.vue
+++ b/src/website/pages/index.vue
@@ -13,10 +13,9 @@