update to mabras rework

This commit is contained in:
2023-10-29 18:28:05 +01:00
parent 2b59f8719a
commit 0ea65867a8
7 changed files with 69 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
import vue from '@vitejs/plugin-vue';
import * as path from "path";
import { defineConfig, loadEnv } from 'vite';
import zlib from 'zlib';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
@@ -17,30 +18,66 @@ export default defineConfig(({ mode }) => {
server: {
port: 3000,
strictPort: true,
watch: {
usePolling: true
},
proxy: {
'/api/': {
target: `https://${env.API_URL}/`,
target: env.API_URL,
changeOrigin: true,
followRedirects: true,
rewrite: (path) => path.replace(/^\/api/, ''),
rewrite: path => path.replace(/^\/api/, ''),
selfHandleResponse: true,
configure: proxy => {
proxy.on('proxyRes', (proxyRes, req, res) => {
const chunks = [];
proxyRes.on("data", (chunk) => chunks.push(chunk));
proxyRes.on("end", () => {
const buffer = Buffer.concat(chunks);
const encoding = proxyRes.headers["content-encoding"];
const relace = (b: Buffer) => {
let remoteBody = b.toString();
const modifiedBody = remoteBody.replace(env.API_URL, '/api/');
res.write(modifiedBody);
res.end();
}
if (!encoding) {
relace(buffer);
} else if (encoding === "gzip" || encoding === "deflate") {
zlib.unzip(buffer, (err, b) => {
if (!err) {
relace(b);
} else {
console.error(err);
}
});
} else {
console.error(`Unsupported encoding: ${encoding}`);
}
});
});
}
},
'/pocketbase/': {
target: `https://${env.POCKET_BASE_URL}/`,
target: env.POCKET_BASE_URL,
changeOrigin: true,
followRedirects: true,
rewrite: (path) => path.replace(/^\/pocketbase/, ''),
rewrite: path => path.replace(/^\/pocketbase/, ''),
},
'/appraisal/': {
target: `https://${env.EVEPRAISAL_URL}/`,
target: env.EVEPRAISAL_URL,
changeOrigin: true,
followRedirects: true,
rewrite: (path) => path.replace(/^\/appraisal/, ''),
rewrite: path => path.replace(/^\/appraisal/, ''),
},
'/esi/': {
target: `https://${env.ESI_URL}/latest/`,
target: env.ESI_URL,
changeOrigin: true,
followRedirects: true,
rewrite: (path) => path.replace(/^\/esi/, ''),
rewrite: path => path.replace(/^\/esi/, ''),
headers: {
'User-Agent': env.ESI_USER_AGENT
},