diff --git a/.env b/.env index 3b4e390b..7b94da02 100644 --- a/.env +++ b/.env @@ -17,5 +17,5 @@ MONGO_PORT=27017 MONGO_DATABASE_NAME=blog ## frontend -API_BASE_URL=http://127.0.0.1:8000 -INTERNAL_API_BASE_URL=http://app +NUXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8000 +NUXT_INTERNAL_API_BASE_URL=http://app diff --git a/backend/Dockerfile b/backend/Dockerfile index 70ae6ac6..6afeb70c 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,20 +1,11 @@ FROM golang:1.21 as build - WORKDIR /dist COPY . . - -# Adjust the ARCH if needed - eg amd64 or arm64v8 ENV GOARCH=amd64 CGO_ENABLED=0 - RUN go mod download - -# Build the binary RUN go build -v -o app ./main.go && chmod +x app FROM alpine:latest as production - COPY --from=build /dist /usr/bin - EXPOSE 80 - CMD ["app", "serve", "-port=80"] \ No newline at end of file diff --git a/compose.yaml b/compose.yaml index 3ea0e597..b9e19dd9 100644 --- a/compose.yaml +++ b/compose.yaml @@ -5,15 +5,16 @@ services: build: context: ./frontend dockerfile: Dockerfile + target: develop depends_on: - app ports: - "3000:3000" volumes: - - ./frontend:/app + - ./frontend:/opt/app environment: - API_BASE_URL: ${API_BASE_URL} - INTERNAL_API_BASE_URL: ${INTERNAL_API_BASE_URL} + NUXT_PUBLIC_API_BASE_URL: ${NUXT_PUBLIC_API_BASE_URL} + NUXT_INTERNAL_API_BASE_URL: ${NUXT_INTERNAL_API_BASE_URL} command: > sh -c "npm install; npm run dev --host" diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 3d06f6d7..1ff2fc89 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,11 +1,17 @@ -FROM node:21.6-alpine3.18 - -WORKDIR /app - +FROM node:20.11-alpine AS base +WORKDIR /opt/app COPY . . - RUN npm install +FROM base AS develop EXPOSE 3000 +CMD ["npm", "run", "dev", '--host'] -CMD npm run dev --host \ No newline at end of file +FROM base as build +RUN npm run build + +FROM node:20.11-alpine as production +WORKDIR /opt/app +COPY --from=build /opt/app/.output . +EXPOSE 3000 +CMD ["node", "server/index.mjs"] diff --git a/frontend/composables/urlResolver.ts b/frontend/composables/urlResolver.ts index f5fd31a4..6569b8b3 100644 --- a/frontend/composables/urlResolver.ts +++ b/frontend/composables/urlResolver.ts @@ -1,9 +1,9 @@ function baseUrl() { const {internalApiBaseUrl, public: p} = useRuntimeConfig() - const url = process.client ? p.publicApiBaseUrl : internalApiBaseUrl; + const url = process.client ? p.apiBaseUrl : internalApiBaseUrl; return { - publicApiBaseUrl: p.publicApiBaseUrl.replace(/\/$/, ""), + publicApiBaseUrl: p.apiBaseUrl.replace(/\/$/, ""), internalApiBaseUrl: internalApiBaseUrl?.replace(/\/$/, ""), apiBaseUrl: url.replace(/\/$/, "") }; diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts index 762e5e63..dd0b592b 100644 --- a/frontend/nuxt.config.ts +++ b/frontend/nuxt.config.ts @@ -8,9 +8,9 @@ export default defineNuxtConfig({ '@vueuse/nuxt','@pinia/nuxt' ], runtimeConfig: { - internalApiBaseUrl: process.env.INTERNAL_API_BASE_URL, + internalApiBaseUrl: '', public: { - publicApiBaseUrl: process.env.API_BASE_URL, + apiBaseUrl: '', } } }) diff --git a/frontend/plugins/axios.js b/frontend/plugins/axios.js deleted file mode 100644 index 7b7e3499..00000000 --- a/frontend/plugins/axios.js +++ /dev/null @@ -1,5 +0,0 @@ -import axios from "axios"; -export default defineNuxtPlugin((nuxtApp)=>{ - nuxtApp.vueApp.use(axios) - axios.defaults.baseURL="http://127.0.0.1:8000/api/" -}) \ No newline at end of file