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

SockJS issue when port is different than 8080 #345

Closed
jpoo90 opened this issue Aug 29, 2017 · 4 comments
Closed

SockJS issue when port is different than 8080 #345

jpoo90 opened this issue Aug 29, 2017 · 4 comments
Labels

Comments

@jpoo90
Copy link

jpoo90 commented Aug 29, 2017

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
After executing an AJAX request, this errors from sock start populating the console

preactsockerror

If the current behavior is a bug, please provide the steps to reproduce.

  • Run a server on port 8080
  • npm start from the preact-cli created project.
  • Use fetch to request something.
  • Sock will start logging errors into the console.

What is the expected behavior?
I think sock should be mapped to the port were the app is running.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information.

  • node version: 8.1.4
  • npm version: 5.3.0
  • Operating system: osX
  • preact-cli: 1.4.1
@filoxo
Copy link

filoxo commented Sep 1, 2017

Your server is not actually running on 8080, which you might be expecting. The CLI will randomly choose a port to run on if 8080 is taken (see the URL in your browser), but there is definitely a bug in that the hmr script isn't using that randomly-selected port. I came here to report this as well.

@didierfranc
Copy link

Same here

@developit developit added the bug label Dec 25, 2017
@developit
Copy link
Member

Yup - looks like we're not passing port correctly.

@oieduardorabelo
Copy link

oieduardorabelo commented Sep 13, 2018

hey all 👋,

I tried to reproduce this bug but seems it is fixed on current stable version,

$ npm install -g preact-cli and test scenario below...

🐛 💥 🐞


[TEST SCENARIO]

  • new file $ touch same.js with:
const http = require('http');

const PORT = 8080;

const server = http.createServer((req, res) => {
  res.end(`Hello http://localhost:${PORT}!`);
});

server.listen(PORT, () => {
  console.log(`Running on`, server.address())
});
  • using $ node same.js
  • new preact project $ preact create simple testy
  • running $cd testy and $ npm install
  • resolves to "preact-cli": "^2.0.0"
  • and $ npm start

screen shot 2018-09-13 at 7 30 44 pm

screen shot 2018-09-13 at 7 30 48 pm

  • opening it in my browser, Chrome Version 71.0.3544.2 (Official Build) canary (64-bit):

screen shot 2018-09-13 at 7 32 28 pm

  • my index.js:
import "./style";
import { Component } from "preact";

export default class App extends Component {
  componentDidMount() {
    console.log(`fetch:start`);
    fetch("https://dog.ceo/api/breeds/image/random")
      .then(res => res.json())
      .then(data => {
        console.log(`fetch:done - .then`);
        console.log(data);
      })
      .catch((err) => {
        console.log(`fetch:done - .catch`);
        console.log(err);
      });
  }
  render() {
    return (
      <div>
        <h1>Hello, World!</h1>
      </div>
    );
  }
}
  • no socket errors after fetch/ajax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants