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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip undefined proxy entry #9622

Merged
merged 7 commits into from Aug 16, 2022
Merged

fix: skip undefined proxy entry #9622

merged 7 commits into from Aug 16, 2022

Conversation

lbiceman
Copy link
Contributor

fix(vite/node): Cannot read properties of undefined: configure

@sapphi-red
Copy link
Member

Please don't remove the PR template.


When does this happen? IIUC when the config is like below?

export default defineConfig({
  server: {
    proxy: {
      '/api': undefined
    }
  }
}

In that case, I think it's better to skip from here with if (!opt) return.

Object.keys(options).forEach((context) => {
let opts = options[context]
if (typeof opts === 'string') {
opts = { target: opts, changeOrigin: true } as ProxyOptions
}
const proxy = httpProxy.createProxyServer(opts) as HttpProxy.Server

Then, we won't need to check if the value is undefined or not in proxies.

const [proxy, opts] = proxies[context]

@lbiceman
Copy link
Contributor Author

import { defineConfig, loadEnv } from 'vite'
export default function ({ command, mode }) {
const root = process.cwd();
const env = loadEnv(mode, root);
return defineConfig({
base: './',
server: {
host: true,
port: 9095,
proxy: {
'/logicFlow': env.VITE_SERVER_ADDR
}
}
})
}

@patak-dev
Copy link
Member

@lbiceman, following up in case you're waiting for us here. I think you should implement @sapphi-red suggestion to move this PR forward. if you are busy, don't worry, we'll modify the PR at one point and merge it. Thanks again!

@lbiceman
Copy link
Contributor Author

@sapphi-red function proxyMiddleware。When the options[context] is undefined, the current loop should be skipped。

@sapphi-red sapphi-red changed the title fix(vite/node): Cannot read properties of undefined: configure fix: skip undefined proxy entry Aug 16, 2022
@patak-dev patak-dev merged commit e396d67 into vitejs:main Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants