Initial commit of dashboard project
This commit is contained in:
39
pvcweb-vue/vite.config.js
Normal file
39
pvcweb-vue/vite.config.js
Normal file
@ -0,0 +1,39 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:7370',
|
||||
changeOrigin: true,
|
||||
configure: (proxy, options) => {
|
||||
proxy.on('proxyReq', (proxyReq, req, res) => {
|
||||
const apiUri = req.headers['x-api-uri'];
|
||||
if (apiUri) {
|
||||
const targetUrl = new URL(apiUri);
|
||||
options.target = targetUrl.origin;
|
||||
proxyReq.setHeader('host', targetUrl.host);
|
||||
|
||||
// Rewrite path to include the API URI path
|
||||
const apiPath = targetUrl.pathname;
|
||||
const requestPath = req.url.replace('/api', '');
|
||||
proxyReq.path = `${apiPath}${requestPath}`;
|
||||
|
||||
console.log(`Proxying to: ${options.target}${proxyReq.path}`);
|
||||
}
|
||||
|
||||
if (req.headers['x-api-key']) {
|
||||
proxyReq.setHeader('X-Api-Key', req.headers['x-api-key']);
|
||||
}
|
||||
});
|
||||
|
||||
proxy.on('error', (err, req, res) => {
|
||||
console.error('Proxy error:', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user