Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Cannot use vite proxy with 0.4.x #1180

Closed
2 tasks done
srikrsna opened this issue Dec 26, 2023 · 6 comments
Closed
2 tasks done

[Bug?]: Cannot use vite proxy with 0.4.x #1180

srikrsna opened this issue Dec 26, 2023 · 6 comments
Labels
bug Something isn't working vinxi related to vinxi

Comments

@srikrsna
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 馃槸

This is my config:

import { defineConfig } from "@solidjs/start/config";

export default defineConfig({
  server: {
    fs: {
      allow: ["../.."],
    },
    proxy: {
      "/api": {
        target: "http://localhost:3001",
        changeOrigin: true,
      },
    },
  },
  start: {
    ssr: false,
    server: {
      preset: "static",
    },
  },
});

The requests that start with /api are not forwarded to 3001.

I also tried moving the config to the new server part:

import { defineConfig } from "@solidjs/start/config";

export default defineConfig({
  server: {
    fs: {
      allow: ["../.."],
    },
  },
  start: {
    ssr: false,
    server: {
      preset: "static",
      devProxy: {
        "/api": {
          target: "http://localhost:3001",
          changeOrigin: true,
        },
      },
    },
  },
});

Expected behavior 馃

Requests should be forwarded to configured proxy targets. This use to work prior to 0.4.0 with a similar config:

import solid from "solid-start/vite";
import { defineConfig } from "vite";

export default defineConfig({
  define: {
    "import.meta.vitest": "undefined",
  },
  plugins: [solid({ ssr: false })],
  server: {
    proxy: {
      "/api": {
        target: "http://localhost:3001",
        changeOrigin: true,
      },
    },
  },
});

Steps to reproduce 馃暪

Steps:

  1. Use the any proxy route
  2. Start the dev server and open the proxy route
  3. Instead of forwarding it will serve the index file.

Context 馃敠

No response

Your environment 馃寧

No response

@srikrsna srikrsna added the bug Something isn't working label Dec 26, 2023
@nksaraf
Copy link
Member

nksaraf commented Dec 26, 2023

Yeah I had removed some of the proxy features initially from vinxi to keep things simple, since a proxy can be just another API route.

But I might bring it back, most likely as the nitro config and not the vite config.

What is the use case for the proxy? and does it need to be there both in dev and prod?

@srikrsna
Copy link
Author

srikrsna commented Dec 26, 2023

I only need it for dev. My use case is to just to forward it to an existing backend. In prod they will be served by the same server.

@srikrsna
Copy link
Author

But I might bring it back, most likely as the nitro config and not the vite config.

I think this is a bit confusing, I was initially looking for the fs option in the server but had to use the vite one. The proxy config is a similar story

@vincentfretin
Copy link

I have a similar use case, currently I'm using solid without solid start, but with webpack and webpack dev server with the following configuration for development:

  devServer: {
    historyApiFallback: {
      rewrites: [
        {
          from: /^\/scenes\/.*$/,
          to: function (context) {
            return "/public" + context.parsedUrl.pathname;
          },
        }
      ],
    },
    proxy: {
      "/api/tts": {
        target: "http://127.0.0.1:59125",
      },
      "/openai-worker/completions": {
        target: "http://localhost:3000",
        pathRewrite: { "^/openai-worker": "" },
      }
    }
  }

"/api/tts" proxy to http://127.0.0.1:59125/api/tts
"/openai-worker/completions" proxy to "http://localhost:3000/completions"
"/scenes/*" proxy to the public/scenes/ folder that is several GB of files.
On production I'm using nginx with similar rules.

I need support for those proxy in development to be able to switch to vite/nitro/vinxi.

@nksaraf
Copy link
Member

nksaraf commented Dec 27, 2023

I guess one pending question is, that is it okay for there to be proxies that are dev only (like vite) or proxies should be dev + prod by default, with maybe some way of opting out on either side.. hmm, going to create an issue in vinxi for this.

@nksaraf
Copy link
Member

nksaraf commented Dec 28, 2023

Should be fixed with vinxi:0.0.58.

You have to use the start.server.devProxy option to configure proxies.

export default defineConfig({
	start: {
		server: {
			devProxy: {
		      "/api/tts": {
		        target: "http://127.0.0.1:59125",
		      },
		      "/openai-worker/completions": {
		        target: "http://localhost:3000/",
		        pathRewrite: { "^/openai-worker": "" },
		      }
			}
		}
	}
})

@nksaraf nksaraf closed this as completed Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vinxi related to vinxi
Projects
None yet
Development

No branches or pull requests

3 participants