diff --git a/.env b/.env new file mode 100644 index 0000000..9c35098 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +VITE_PORT=3001 +TEXTS_API_URL=http://localhost:3000 \ No newline at end of file diff --git a/backend/.env b/backend/.env new file mode 100644 index 0000000..2d15c51 --- /dev/null +++ b/backend/.env @@ -0,0 +1,2 @@ +PORT=3000 +TEXTS_PATH=C:\src\patois\texts \ No newline at end of file diff --git a/backend/package-lock.json b/backend/package-lock.json index d3c5b9a..da767b4 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -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", diff --git a/backend/package.json b/backend/package.json index e36f684..38191b3 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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" } } - diff --git a/backend/server.js b/backend/server.js index a4f94ed..2674953 100644 --- a/backend/server.js +++ b/backend/server.js @@ -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()) diff --git a/src/services/textService.js b/src/services/textService.js index 2025507..23d1532 100644 --- a/src/services/textService.js +++ b/src/services/textService.js @@ -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() { diff --git a/start.bat b/start.bat index 6d39c9c..d52b7dc 100644 --- a/start.bat +++ b/start.bat @@ -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. diff --git a/vite.config.js b/vite.config.js index bbcf80c..7f78eda 100644 --- a/vite.config.js +++ b/vite.config.js @@ -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({ - plugins: [vue()], +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd()) + return { + plugins: [vue()], + server: { + port: parseInt(env.VITE_PORT) || 3001 + } + } })