Skip to content

Commit

Permalink
[Upd #151] Updated environment variables to meet Vite specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
LaChope committed Jan 25, 2024
1 parent 951b39b commit 510d514
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
API_URL=http://localhost:9999
CONTEXT=''
ADMIN_REGISTRATION_ONLY=false
VITE_API_URL=http://localhost:9999
VITE_CONTEXT=''
VITE_ADMIN_REGISTRATION_ONLY=false
6 changes: 3 additions & 3 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
API_URL=https://kbss.felk.cvut.cz/fta-fmea-server
CONTEXT='/fta-fmea'
ADMIN_REGISTRATION_ONLY=false
VITE_API_URL=https://kbss.felk.cvut.cz/fta-fmea-server
VITE_CONTEXT='/fta-fmea'
VITE_ADMIN_REGISTRATION_ONLY=false
2 changes: 1 addition & 1 deletion src/components/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const Login = () => {
>
Sign In
</Button>
{process.env.ADMIN_REGISTRATION_ONLY !== "true" && (
{import.meta.env.VITE_ADMIN_REGISTRATION_ONLY !== "true" && (
<Grid container>
<Grid item>
<MaterialLink variant="body2" component={RouterLink} to={ROUTES.REGISTER}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/routes/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const AppRoutes = () => {
<BrowserRouter /*history={appHistory}*/>
<Routes>
{/*TODO: revisit routing, this is hotfix to support react-router v6*/}
{process.env.ADMIN_REGISTRATION_ONLY === "true"
{import.meta.env.VITE_ADMIN_REGISTRATION_ONLY === "true"
? <Route path={ROUTES.REGISTER} element={<AdminRoute><Register/></AdminRoute>}/>
: <Route path={ROUTES.REGISTER} element={<PublicRoute restricted={true}><Register/></PublicRoute>}/>
}
Expand Down
3 changes: 1 addition & 2 deletions src/services/utils/axiosUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {appHistory} from "@components/routes/AppRoutes";
import {ROUTES} from "@utils/constants";

const axiosClient = axios.create({
// @ts-ignore
baseURL: window.__config__.API_URL
baseURL: import.meta.env.VITE_API_URL
});

axiosClient.interceptors.response.use(
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "none",
"module": "ESNext",
"jsx": "react",
"target": "es6",
"moduleResolution": "node",
Expand All @@ -19,7 +19,8 @@
"es2017",
"dom",
"dom.iterable"
]
],
"types": ["vite/client"]
},
"include": [
"src/*.ts",
Expand Down
9 changes: 9 additions & 0 deletions vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="vite/client" />
interface ImportMetaEnv {
VITE_API_URL: string;
VITE_ADMIN_REGISTRATION_ONLY: string;
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}

0 comments on commit 510d514

Please sign in to comment.