Ajout des variables d'environemment

This commit is contained in:
ElPoyo
2025-09-29 11:56:48 +02:00
parent b4a468c14b
commit 45f76cc5c8
8 changed files with 42 additions and 11 deletions

2
.env Normal file
View File

@@ -0,0 +1,2 @@
VITE_PORT=3001
TEXTS_API_URL=http://localhost:3000

2
backend/.env Normal file
View File

@@ -0,0 +1,2 @@
PORT=3000
TEXTS_PATH=C:\src\patois\texts

View File

@@ -10,6 +10,7 @@
"license": "MIT",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^17.2.2",
"express": "^4.18.2",
"multer": "^1.4.5-lts.1"
},
@@ -309,6 +310,18 @@
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/dotenv": {
"version": "17.2.2",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.2.tgz",
"integrity": "sha512-Sf2LSQP+bOlhKWWyhFsn0UsfdK/kCWRv1iuA2gXAwt3dyNabr6QSj00I2V10pidqz69soatm9ZwZvpQMTIOd5Q==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",

View File

@@ -8,16 +8,21 @@
"start": "node server.js",
"dev": "nodemon server.js"
},
"keywords": ["patois", "franco-provençal", "api", "express"],
"keywords": [
"patois",
"franco-provençal",
"api",
"express"
],
"author": "",
"license": "MIT",
"dependencies": {
"express": "^4.18.2",
"cors": "^2.8.5",
"dotenv": "^17.2.2",
"express": "^4.18.2",
"multer": "^1.4.5-lts.1"
},
"devDependencies": {
"nodemon": "^3.0.1"
}
}

View File

@@ -3,12 +3,18 @@ import cors from 'cors'
import fs from 'fs/promises'
import path from 'path'
import { fileURLToPath } from 'url'
import dotenv from 'dotenv'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
/** Configuration dotenv
* Permet de charger les variables d'environnement depuis un fichier .env
* */
dotenv.config()
const app = express()
const PORT = process.env.PORT || 3001
const PORT = process.env.PORT
// Middleware
app.use(cors())

View File

@@ -2,7 +2,7 @@
* Service pour communiquer avec l'API backend des textes
*/
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001/api'
const API_BASE_URL = import.meta.env.TEXTS_API_URL
export class TextService {
constructor() {

View File

@@ -19,9 +19,6 @@ start "Frontend Vue.js" cmd /k "npm run dev"
echo.
echo ==============================================
echo Application demarree avec succes !
echo.
echo Frontend: http://localhost:5173
echo API: http://localhost:3001
echo ==============================================
echo.
echo Fermez cette fenetre quand vous voulez arreter l'application.

View File

@@ -1,7 +1,13 @@
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vite.dev/config/
export default defineConfig({
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd())
return {
plugins: [vue()],
server: {
port: parseInt(env.VITE_PORT) || 3001
}
}
})