Skip to content

Commit

Permalink
feat: api key 은닉 (#106)
Browse files Browse the repository at this point in the history
* feat: vite 프록시 설정

* feat: apiClient baseURL주소 수정

* refactor: manualChunks 옵션 제거
  • Loading branch information
khj0426 authored Dec 3, 2023
1 parent 5065e7f commit 3acc475
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/apis/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import { TOKEN_KEY } from '@/constants'

const apiClient = axios.create({
baseURL: import.meta.env.VITE_API_KEY,
baseURL: '/api',
})

apiClient.interceptors.request.use(
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"include": ["src","src/*"],
"references": [{ "path": "./tsconfig.node.json" }]
}
47 changes: 30 additions & 17 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
import path from 'path'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import svgr from 'vite-plugin-svgr'

export default defineConfig({
plugins: [react(), svgr()],
resolve: {
alias: [{ find: '@', replacement: path.resolve(__dirname, 'src') }],
},
// 환경 변수 로드
export default ({ mode }) => {
const env = { ...process.env, ...loadEnv(mode, process.cwd()) }

build: {
rollupOptions: {
external: (id) => {
if (id.includes('/node_modules/@mswjs')) {
return true
}
if (id.includes('/src/mocks')) {
return true
}
return defineConfig({
plugins: [react(), svgr()],
resolve: {
alias: [{ find: '@', replacement: path.resolve(__dirname, 'src') }],
},
build: {
rollupOptions: {
external: (id) => {
if (id.includes('/node_modules/@mswjs')) {
return true
}
if (id.includes('/src/mocks')) {
return true
}
},
},
},
server: {
proxy: {
'/api': {
target: env.VITE_API_KEY,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
},
})
})
}

0 comments on commit 3acc475

Please sign in to comment.