-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
49 lines (45 loc) · 1.39 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { defineConfig } from "vite";
import path from "path";
import reactPlugin from "@vitejs/plugin-react";
import dotenv from "dotenv";
dotenv.config();
const apiBaseURL = process.env.VITE_API_BASE_URL;
const itemsPerPage = process.env.VITE_ITEMS_PER_PAGE;
const librariesBaseURL = process.env.LIBRARIES_BASE_URL;
const librariesAPIKey = process.env.LIBRARIES_API_KEY;
const port = parseInt(process.env.PORT || "3000", 10);
if (!apiBaseURL || !librariesBaseURL || !librariesAPIKey || !itemsPerPage) {
throw new Error(
"Missing environment variables. Please check your .env file."
);
}
export default defineConfig({
plugins: [reactPlugin()],
resolve: {
alias: {
"@shared": path.resolve(__dirname, "src/shared"),
"@home": path.resolve(__dirname, "src/home"),
"@package": path.resolve(__dirname, "src/package"),
},
},
server: {
port,
open: true,
proxy: {
[apiBaseURL]: {
target: librariesBaseURL, // Replace with your API server
changeOrigin: true,
rewrite: (path) => {
const url: URL | string = new URL(
path,
process.env.LIBRARIES_BASE_URL
);
// Append the API key as a search parameter
url.searchParams.append("api_key", librariesAPIKey);
url.searchParams.append("per_page", itemsPerPage);
return url.toString();
},
},
},
},
});