From c5282532fbb93822acacb373efe15866af4cac3b Mon Sep 17 00:00:00 2001 From: Platon Yasev Date: Tue, 16 May 2023 13:57:54 +0300 Subject: [PATCH] Get api url from env --- .env | 1 + .env.local.example | 1 + src/api.js | 4 ++-- vite.config.ts | 40 +++++++++++++++++++++------------------- 4 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 .env create mode 100644 .env.local.example diff --git a/.env b/.env new file mode 100644 index 0000000..cf067ee --- /dev/null +++ b/.env @@ -0,0 +1 @@ +VITE_API_URL=https://postnet.dev.selftech.ru diff --git a/.env.local.example b/.env.local.example new file mode 100644 index 0000000..cf067ee --- /dev/null +++ b/.env.local.example @@ -0,0 +1 @@ +VITE_API_URL=https://postnet.dev.selftech.ru diff --git a/src/api.js b/src/api.js index 9be913b..6c6378a 100644 --- a/src/api.js +++ b/src/api.js @@ -4,13 +4,13 @@ import { STATUSES } from "./config"; import { usePointSelection } from "./stores/usePointSelection"; import { usePendingPointsFilters } from "./stores/usePendingPointsFilters"; -export const BASE_URL = "https://postnet-dev.selftech.ru"; +export const BASE_URL = import.meta.env.VITE_API_URL; export const api = axios.create({ baseURL: import.meta.env.MODE === "development" ? "http://localhost:5173/" - : `${BASE_URL}/`, + : BASE_URL, withCredentials: true, xsrfHeaderName: "X-CSRFToken", xsrfCookieName: "csrftoken", diff --git a/vite.config.ts b/vite.config.ts index 2cd45ce..7a5e279 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,28 +1,30 @@ -import { defineConfig } from "vite"; +import { defineConfig, loadEnv } from "vite"; import react from "@vitejs/plugin-react"; import svgr from "vite-plugin-svgr"; -const BASE_URL = "https://postnet-dev.selftech.ru/"; +export default defineConfig(({ mode }) => { + // @ts-ignore + const env = loadEnv(mode, process.cwd()); -// https://vitejs.dev/config/ -export default defineConfig({ - base: "/", - plugins: [svgr(), react()], - server: { - proxy: { - "/account": BASE_URL, - "/api": BASE_URL, + return { + base: "/", + plugins: [svgr(), react()], + server: { + proxy: { + "/account": env.VITE_API_URL, + "/api": env.VITE_API_URL, + }, }, - }, - css: { - preprocessorOptions: { - less: { - modifyVars: { - "primary-color": "#CC2222FF", - "border-radius-base": "5px", + css: { + preprocessorOptions: { + less: { + modifyVars: { + "primary-color": "#CC2222FF", + "border-radius-base": "5px", + }, + javascriptEnabled: true, }, - javascriptEnabled: true, }, }, - }, + }; });