4

I have a Pixelbook on Chrome 79. In my terminal (Crostini), I run a simple Express app:

const express = require('express');
const app = express();

app.get('/', (req, res) => {
    res.send('Hello!');
});

const PORT = 8080;

app.listen(PORT, () => console.log(`Listening on port ${PORT}...`));

And try it in the browser at localhost:8080 and I get the localhost refused to connect error.

If I use the Angular CLI tool to make a boilerplate Angular project and use ng serve, it tells me it's listening at localhost:4200 - which I try and it does work.

What's the difference? How do I get my app to work on localhost?

I feel like I had this working the last time I tried it a couple months ago and now it's just not working and I can't tell why. I've tried using other ports and restarting my computer and nothing changes.

Edit: I've seen Google demo that the port forwarding should work automatically here: https://youtu.be/pRlh8LX4kQI?t=1160 - but it doesn't seem like it is for me.

Edit 2: If I find the IP of my container with ip addr show | grep inet (for me it was 100.115.92.199) and try that at port 8080 it works. Also, I found someone on Reddit reporting the same issue (link). So I think the automatic port forwarding is broken.

Kenmore
  • 1,525
  • 3
  • 16
  • 39
  • works for me, how are you testing your code? You could also have `console.log('received request')` in your handler for `app.get('/'...)` (right above or below `res.send()` to see when someone tries to connect to your page. – Jeremi G Jan 09 '20 at 05:52
  • The file is called `index.js` so I'm in the directory and run `node .`. My `Listening...` message appears, as expected. I did try adding a log when a request is received and it never gets triggered. – Kenmore Jan 09 '20 at 05:59
  • So, your request doesn't reach the back-end. Probably means that your computer isn't letting your index.js listen and is silently denying it – Jeremi G Jan 09 '20 at 06:03
  • Well it seems the port isn't actually being forwarded from the Linux container to Chrome OS. I was just under the impression that that is done automatically - at least I've seen them demo that (edited post with link) - so if it's not working like it's supposed to IDK what to do. – Kenmore Jan 09 '20 at 06:05

2 Answers2

1

The network interface integration improved with Chrome 80: try updating to the beta version

  1. Go to settings
  2. At the bottom of the left panel, select About Chrome OS.
  3. Select "Detailed build information" or "Additional details"
  4. Next to "Channel," select Change channel.
  5. Pick "Beta"
C. Reed
  • 2,382
  • 7
  • 30
  • 35
  • I tried this and now my terminal does not work at all. It says: `vmshell is not supported on this version of Chrome The command vmshell exited with status code 1. (R)econnect, (C)hoose another connection, or E(x)it?` and the first 2 options don't do anything. – Kenmore Jan 10 '20 at 00:23
  • Okay found a fix: Make sure you have the Secure Shell App installed and enabled: https://chrome.google.com/webstore/detail/secure-shell-app/pnhechapfaindjhompbnflcldabbghjo/related – C. Reed Jan 10 '20 at 04:29
  • After installing that and restarting, terminal works. However my app port is still not being forwarded to localhost. – Kenmore Jan 10 '20 at 18:12
1

I also have a Pixelbook on Chrome 79. Your code will work on Firefox. To make it work on the Chrome browser you have to pass the host parameter to app.listen().

const express = require('express');
const app = express();

app.get('/', (req, res) => {
    res.send('Hello!');
});

const PORT = 8080;
const HOST = 'localhost';

app.listen(PORT, HOST, () => console.log(`Listening on port ${PORT}...`));
  • Yes, setting the host fixes my issues. I still feel like it used to work without this but maybe I'm wrong. – Kenmore Jan 20 '20 at 07:08