-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.js
More file actions
65 lines (60 loc) · 2.05 KB
/
vite.config.js
File metadata and controls
65 lines (60 loc) · 2.05 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/** @type {import('vite').UserConfig} */
import {defineConfig, loadEnv} from "vite";
import { resolve } from 'path';
// Configuration
//let apiKEY = "<YOUR_KEY>"; // add your API key
//let platformUrl = 'https://app.timefold.ai'; // adjust your platform (usually app.timefold.ai)
//
let apiKEY = '<DUMMY>'; // add your API key
let platformUrl = 'http://localhost:9000'; // adjust your platform (usually app.timefold.ai)
// Rewrite the path for the local proxy
function rewritePath(p, env) {
p = p.replace(/^\/proxy/,'');
if(platformUrl.match(".*localhost.*")) {
return p.replace(/^\/employee-shifts/, '/v1/')
} else {
return p.replace(/^\/employee-shifts/, '/api/models/employee-scheduling/v1');
}
}
/*
This proxy serves 2 purposes:
- Add the API key so it's not exposed in the UI
- Rewrite the path based on the configured platformUrl
*/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
return {
// Setup environment variables for build
define: {
__PROD_API_URL__: JSON.stringify(env.VITE_PROD_API_URL),
__STAGING_API_URL__: JSON.stringify(env.VITE_STAGING_API_URL),
__ESS_MODEL_PATH__: JSON.stringify(env.VITE_ESS_MODEL_PATH),
__ESS_MODEL_MAIN_RESOURCE__: JSON.stringify(env.VITE_ESS_MODEL_MAIN_RESOURCE),
},
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
}
},
},
// Setup server for local development.
server: {
proxy: {
'/proxy': {
target: platformUrl,
secure: false,
changeOrigin: true,
rewrite: p => rewritePath(p, env),
headers: {
'X-API-KEY': apiKEY,
},
configure: (proxy, options) => {
proxy.on('proxyReq', (proxyReq, req, res) => {
console.log(`Proxied request to: ${proxyReq.path}`);
});
},
}
}
}
}});