vue-cli icon indicating copy to clipboard operation
vue-cli copied to clipboard

sockjs-node (Not Found)

Open mavajee opened this issue 8 years ago • 26 comments

Version

3.0.0-beta.15

Reproduction link

https://jsfiddle.net/w0jg8bdr/

Steps to reproduce

Use with nginx

What is expected?

HMR working with nginx

What is actually happening?

I use 3 version of vue cli and nginx. And each vue app have different sockjs-node path.

vue cli 10 have path 0.0.0.0:8082/sockjs-node/*** and it's work

vue cli 12 have path http://localhost.com:8082/sockjs-node/*** and it's work to

vue cli 15 have path http://localhost.com/sockjs-node/*** and it's not work. How you can see port is missing

UPD. If i run app on 0.0.0.0:8082 without nginx all work fine


maybe this commit is the reason or this

It's bug or just I not correct config my app?

mavajee avatar Jun 05 '18 06:06 mavajee

I found the trouble, in this commit line 70, if remove '?/sockjs-node', all work

mavajee avatar Jun 05 '18 06:06 mavajee

versions 10 has the best correct sockjs path to dev serve from any host name.

mavajee avatar Jun 05 '18 07:06 mavajee

Umm, it should not work like that. What is baseUrl in your vue.config.js?

jkzing avatar Jun 05 '18 08:06 jkzing

@jkzing I try use baseUrl but it not work. in ver 10 I used absolute path to work with nginx

config.output.publicPath = http://${host}:${port}/

because need all request send to webpack dev server

UPD: I try '/' baseUrl UPD: All files on dev server located in '/'.

mavajee avatar Jun 05 '18 10:06 mavajee

@mavajee you should not be mutating publicPath because this value needs to be used in other places in addition to the wepback config. Use the baseUrl option.

yyx990803 avatar Jun 05 '18 13:06 yyx990803

@yyx990803 Maybe we could check that and display the like of Don't change webpack 'ouput.publicPath' directly, use vue.config.js 'baseUrl' instead.

Akryum avatar Jun 05 '18 13:06 Akryum

@Akryum that would be nice although it's a bit difficult to precisely detect that

yyx990803 avatar Jun 05 '18 14:06 yyx990803

I guess OP's usage is like having a baseUrl: 'http://localhost:8082/' in vue.config.js.

With a nginx config like:

server {
  listen 8082 default_server;
  location / {
    proxy_pass  http://localhost:8080;
    proxy_set_header Host $host;
  }
}

Then open http://localhost:8082 in browser.

In above case, current strategy to fix the socket url to '/sockjs-node' is not enough, maybe we need to fix it to 'http://localhost:8080/sockjs-node'.

jkzing avatar Jun 05 '18 15:06 jkzing

Thank you for answers. I will check it tomorrow.

What if make '/sockjs-node' url same absolute dev server url. Anyway HMR and sockjs work only with dev server

mavajee avatar Jun 05 '18 15:06 mavajee

@jkzing, hi, now it work for me, but if i put to baseUrl absolute url, I have this (just incorrect display, but all work) image

vue.config.js

const path = require('path')

const host = '0.0.0.0'
const port = 8085

module.exports = {
  lintOnSave: false,
  baseUrl: `http://${host}:${port}/`,

  devServer: {
    port,
    host,
    hotOnly: true,
    disableHostCheck: true,
    clientLogLevel: 'warning',
    inline: true,
    headers: {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
      'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization'
    },
  }
}

mavajee avatar Jun 06 '18 05:06 mavajee

and about historyApiFallback, just my usage situations. If use absolute url, it's will make some troubles.

mavajee avatar Jun 06 '18 06:06 mavajee

@mavajee Just FYI, if current historyApiFallback not works for you, you can still overwrite it in vue.config.js.

jkzing avatar Jun 06 '18 11:06 jkzing

@jkzing, yes I did it, i think it comment will be helpful for you

mavajee avatar Jun 06 '18 12:06 mavajee

Sorry to bother you guys again with this.

I'm finding a similar issue but I'm not so sure is related to this, so just in case I prefer to drop the comment here.

This one comes when running vue-cli-service serve --host xyz. When running it rise the webpack dev server successfully with everything, but the hot reload it won't work. A further inspection on the error log it shows that the webpack dev server cannot reach sockjs-node:

sockjs.js?9be2:1601 GET http://localhost:8080/sockjs-node/info?t=1528877926478 net::ERR_CONNECTION_REFUSED 

but the webpack dev server was opening in the hostname specified by the --host flag.

In previous versions of vue-cli I was doing the same thing and I didn't got the same problem.

I've got the suspicious that this comes because here:

https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/commands/serve.js#L89

urls.lanUrlForConfig is always undefined when setting a host name through --host flag, therefore it will always spawn sockjs-node to localhost.

But maybe I'm doing something wrong. Am I missing something?

I'm suing webpak 4.12.0 which I believe that is the one that it get install when running vue create myProject

linguamatics-albert avatar Jun 13 '18 08:06 linguamatics-albert

@linguamatics-albert , It's actually a bug of serve command, it should not act like that.

As a work around, you can use devServer.public in vue.config.js to specify your host. Which is included in this PR https://github.com/vuejs/vue-cli/pull/1526.

jkzing avatar Jun 13 '18 11:06 jkzing

I think this issue still happens if you have a path at the end of devServer.public:

devServer: {
    host: '0.0.0.0',
    public: '0.0.0.0:8080/app',
    disableHostCheck: true
},

I can get it to work if I remove /app. As a workaround, I've done this in my vue.config.js for the vue project that's doing the proxying:

proxy: {
    '/app': {
        target: 'http://frontend_app:8081',
        changeOrigin: true,
        pathRewrite: {
            '^/app/sockjs-node': ''
        },
    }
}

This fixes the sockjs-node not found error, however, now hot reload doesn't seem to be working.

srchulo avatar Mar 31 '19 20:03 srchulo

Also, this error only started occurring for me once I upgraded to vue cli 3 from 2.

srchulo avatar Mar 31 '19 20:03 srchulo

Never mind, I thought my above solution worked, but it looks like it doesn't.

srchulo avatar Mar 31 '19 21:03 srchulo

This error is still occuring. I'm working on a multi vue app project that is contained within an nginx layer. Whenever I try to upgrade one of the apps (all using vue-cli 3) to a newer version of the vue-cli, or run yarn upgrade on vue-cli or any of its plugins, this errors occurs.

Any suggested fix?

Goldziher avatar Jul 21 '19 08:07 Goldziher

I used @srchulo's comment and added the following to my vue.config.js and the error went away for me using cli 3.0.

host: '0.0.0.0',
public: '0.0.0.0:8080',
disableHostCheck: true

I'm assuming this only occurs to the dev server and does not happen in production build?

iamface avatar Aug 27 '19 00:08 iamface