Skip to content

Commit

Permalink
feat: add env for api url
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwenjie committed Apr 23, 2021
1 parent 80bd005 commit a84b7db
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_BASE_URL = "https://mockend.com/wwwenjie/react-starter/"
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_BASE_URL = "https://mockend.com/wwwenjie/react-starter/"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
coverage
dist
*.local

# Created by https://www.toptal.com/developers/gitignore/api/react,webstorm,vscode
# Edit at https://www.toptal.com/developers/gitignore?templates=react,webstorm,vscode
Expand Down
3 changes: 1 addition & 2 deletions src/data/Fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import axios from 'axios'

export const fetcher = axios.create({
// baseURL: 'https://mockend.com/wwwenjie/react-starter/',
baseURL: 'https://jsonplaceholder.typicode.com/',
baseURL: import.meta.env.VITE_API_BASE_URL,
headers: {
Accept: 'application/json',
'Content-type': 'application/json',
Expand Down
4 changes: 4 additions & 0 deletions src/interface/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line functional/prefer-type-literal
interface ImportMetaEnv {
readonly VITE_API_BASE_URL: string
}

0 comments on commit a84b7db

Please sign in to comment.