I have setup several VMs provisioned through vagrant, each with their own private network IP. The issue comes up is that for one of the VMs, which I have named netcap_backend, I have set to start a nestjs server but when I try to hit an endpoint on my host computer, it returns with a ECONNREFUSED. I have a simple GET endpoint set directly at 192.168.56.101:3000/. My host computer is running Arch, and this is the provisioning for that specific VM:
config.vm.define "netcap_backend" do |back|
back.vm.hostname = "netcap-backend"
back.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", env['MEM_BACKEND']]
vb.customize ["modifyvm", :id, "--cpus", env['CPU_BACKEND']]
end
back.vm.network "private_network", ip: env['BACKEND_IP'] # 192.165.56.101
back.vm.provision "ScriptRunAsVagrantUser", privileged: false, type:"shell", path: "#{env['PROVISION_PATH']}/prov_netcap_back.sh"
end
And this is what I have for my main.ts in my nest server:
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({
allowedHeaders: '*',
origin: '*',
credentials: true,
});
await app.listen(3000);
}
bootstrap();
What is strange is that this is configured identically to my frontend VM, and that is running a React which my host computer has no problem connecting to, be it with a different IP.
At first when I tried a simple fetch on firefox, I expected the fetch call to return me with a simple Hello World but, it returned me with a CORS issue, hence the additional enableCors() call in my main.ts. But that didn't seem to solve the issue. I then used Postman to ping my route, that's when I saw the ECONNREFUSED. What I then tried is to see if my host computer can actually talk to the VM, which it could as ping 192.168.56.101 executed just fine with no network errors.
A little update: Tried the same setup but on windows and worked perfectly...