universal-vue / uvue

Vue CLI plugin to create universal Vue applications with ease
https://universal-vue.github.io/docs/
MIT License
127 stars 13 forks source link

devServer.proxy: Not working with ssr:serve #49

Closed SwapnilSoni1999 closed 4 years ago

SwapnilSoni1999 commented 4 years ago

By using npm run ssr:serve it is not working with the configuration provided in vue.config.js

image

But when npm run serve is used it is working! Can anyone point me out where I'm wrong or its internal missing feature of uvue or something?

In short:

Additional context

node: v13.12.0
vue-cli: v4.2.3
uvue: 0.1.0
os: ArchLinux
browser: Google Chrome
Lord-Y commented 4 years ago

I have the same problem and spent hours on it :pensive: . Did you figure it out @SwapnilSoni1999 ? If not maybe @chymz can give us a help :thinking: . All my axios requests don't reach my API server

yabab-dev commented 4 years ago

Sorry for late response.

UVue doesn't use webpack dev server, that's why this configuration is ignored. Instead, you can create your own server plugin to use a http proxy middleware.

For example if you use default server adapter or express:

const { createProxyMiddleware } = require('http-proxy-middleware');

export default {
  install(app) {
    if (process.env.NODE_ENV !== 'production') {
      const proxyOptions = {
        target: 'https://api.example.com',
        changeOrigin: true,
        ws: true,
      };

      app.use('/api', createProxyMiddleware(proxyOptions));
    }
  }
}

And install it like explained here: https://universal-vue.github.io/docs/plugins/#server

SwapnilSoni1999 commented 4 years ago

Sorry for late response.

UVue doesn't use webpack dev server, that's why this configuration is ignored. Instead, you can create your own server plugin to use a http proxy middleware.

For example if you use default server adapter or express:

const { createProxyMiddleware } = require('http-proxy-middleware');

export default {
  install(app) {
    if (process.env.NODE_ENV !== 'production') {
      const proxyOptions = {
        target: 'https://api.example.com',
        changeOrigin: true,
        ws: true,
      };

      app.use('/api', createProxyMiddleware(proxyOptions));
    }
  }
}

And install it like explained here: https://universal-vue.github.io/docs/plugins/#server

will checkout surely

SwapnilSoni1999 commented 4 years ago

I have the same problem and spent hours on it . Did you figure it out @SwapnilSoni1999 ? If not maybe @chymz can give us a help . All my axios requests don't reach my API server

same, so Im thinking to learn Nuxt and move my stuff in nuxt