mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
Added .env access to frontend (+ while dockerized)
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
FROM node:latest as build-stage
|
FROM node:latest as build-stage
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package*.json ./
|
COPY ./web/admin-gui/package*.json ./
|
||||||
|
COPY ./.env ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
COPY ./ .
|
COPY ./web/admin-gui/ .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
FROM nginx as production-stage
|
FROM nginx as production-stage
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
COPY --from=build-stage /app/dist /app
|
COPY --from=build-stage /app/dist /app
|
||||||
COPY nginx.conf /etc/nginx/nginx.conf
|
COPY ./web/admin-gui/nginx.conf /etc/nginx/nginx.conf
|
||||||
+6
-2
@@ -1,6 +1,8 @@
|
|||||||
services:
|
services:
|
||||||
backend:
|
backend:
|
||||||
build: .
|
build:
|
||||||
|
context: ./
|
||||||
|
dockerfile: ./Dockerfile.backend
|
||||||
image: gohcms-backend
|
image: gohcms-backend
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
@@ -9,7 +11,9 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- back-net
|
- back-net
|
||||||
frontend:
|
frontend:
|
||||||
build: web/admin-gui/.
|
build:
|
||||||
|
context: ./
|
||||||
|
dockerfile: ./Dockerfile.frontend
|
||||||
image: gohcms-frontend
|
image: gohcms-frontend
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
|
|||||||
Vendored
+1
@@ -1 +1,2 @@
|
|||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
declare const __APP_ENV__: Record<string, string>
|
||||||
@@ -8,8 +8,8 @@ const router = createRouter({
|
|||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'home',
|
name: 'login',
|
||||||
component: Home
|
component: Login
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/debug',
|
path: '/debug',
|
||||||
@@ -17,9 +17,9 @@ const router = createRouter({
|
|||||||
component: Debug
|
component: Debug
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/login',
|
path: '/home',
|
||||||
name: 'login',
|
name: 'home',
|
||||||
component: Login
|
component: Home
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const email = ref('')
|
|||||||
const password = ref('')
|
const password = ref('')
|
||||||
|
|
||||||
function getArticles() {
|
function getArticles() {
|
||||||
fetch(`http://localhost:8080/articles/`, {
|
fetch(`http://localhost:${__APP_ENV__.API_PORT}/articles/`, {
|
||||||
headers: { "Authorization": `Bearer ${useAuthStore().token}` }
|
headers: { "Authorization": `Bearer ${useAuthStore().token}` }
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
@@ -25,7 +25,7 @@ function jwtHandler(apiResponse: jwtFormat): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function login(email: string, password: string): void {
|
function login(email: string, password: string): void {
|
||||||
fetch(`http://localhost:8080/login/`, {
|
fetch(`http://localhost:${__APP_ENV__.API_PORT}/login/`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
email: email,
|
email: email,
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ function jwtHandler(apiResponse: jwtFormat): void {
|
|||||||
isTokenOK.value = true
|
isTokenOK.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO rempalcer tous les :8080 par la var d'env du port de l'API (sinon c un peu dommage)
|
||||||
function login(email: string, password: string): void {
|
function login(email: string, password: string): void {
|
||||||
fetch(`http://localhost:8080/login/`, {
|
fetch(`http://localhost:${__APP_ENV__.API_PORT}/login/`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
email: email,
|
email: email,
|
||||||
@@ -28,7 +29,7 @@ function login(email: string, password: string): void {
|
|||||||
.then(result => {
|
.then(result => {
|
||||||
jwtHandler(result)
|
jwtHandler(result)
|
||||||
if (isTokenOK.value === true) {
|
if (isTokenOK.value === true) {
|
||||||
router.push('/')
|
router.push('/home')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
import { fileURLToPath, URL } from 'node:url'
|
import { fileURLToPath, URL } from 'node:url'
|
||||||
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import { defineConfig } from 'vite'
|
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig(({command, mode}) => {
|
||||||
plugins: [vue()],
|
return {
|
||||||
resolve: {
|
plugins: [vue()],
|
||||||
alias: {
|
resolve: {
|
||||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
alias: {
|
||||||
}
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
define: {
|
||||||
|
__APP_ENV__: {
|
||||||
|
...loadEnv(mode, "./../../", ""), // when running directly | access .env from ./web/admin-gui/
|
||||||
|
...loadEnv(mode, process.cwd(), ""), // when running from docker
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user