I recently switched from Linux to WSL2 (Ubuntu 20.04) on Windows 10. When I run any NodeJs application or a server like Apache or Nginx everything works fine on localhost or 127.0.0.1 but doesn't work when I use my local IP address (192.168.1.65).
netstat -tupln when running node js application
I have tried turning off firewall in windows and wsl but it didn't work.
I enabled the IIS from "Program and Features" and it seems to work fine on localhost and ip. So, I figured it wasn't a problem with the network.
All the post I have read suggest that if the site is accessible through 127.0.0.1 and not through ip then you can configure the server config files for Apache or Nginx. But I reinstalled wsl and am hosting through NodeJs / Express only.
The code for the express app's server.js is:
const express = require("express");
const next = require("next");
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
server.use(express.static("public"));
server.all("*", (req, res) => {
return handle(req, res);
});
server.listen(port, "0.0.0.0", (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
});
All I want to do is access the site on my mobile on the same network.