setupProxy.jsx 727 B

12345678910111213141516171819202122232425
  1. const { createProxyMiddleware } = require("http-proxy-middleware");
  2. const spawnSync = require("child_process").spawnSync;
  3. module.exports = (app) => {
  4. const apiEndpoint = process.env.VITE_API_ENDPOINT;
  5. const useProxy = process.env.VITE_USE_PROXY !== "0";
  6. if (useProxy) {
  7. if (apiEndpoint === undefined) {
  8. // eslint-disable-next-line no-console
  9. console.error(
  10. "You must set your VITE_API_HOST in your .env file or disable proxy"
  11. );
  12. // Sleep to have time to read the messages.
  13. spawnSync("sleep", [1.5]);
  14. }
  15. app.use(
  16. ["/store", "/file", "/execute", "/auth"],
  17. createProxyMiddleware({
  18. target: apiEndpoint,
  19. changeOrigin: true,
  20. })
  21. );
  22. }
  23. };