PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WEBDEV 2024 → Vagrant access Dart webdev server
Vagrant access Dart webdev server
Iniciado por EdwardSMaTeresa, out., 28 2022 6:52 AM - 1 resposta
Membro registado
6 mensagems
Publicado em outubro, 28 2022 - 6:52 AM
I am learning Dart. I already installed Dart, and also the CLI tools (webdev and stagehand).

I successfully made a Dart console app and ran it without any issues. Then I started a bare-bones web app project and I ran the app with the following command:

webdev serve
And it started to run the web app in localhost on port 8080:

Serving web on http://127.0.0.1:8080

I already changed the forwarded port to 8080 in the vagrant file like this:

config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
But I still cannot access/view the Dart web app, so my best guest is that I am doing something wrong with the port forwarding. How can I access my Dart web app running in vagrant from the browser?

I am using an ubuntu box.
Membro registado
8 mensagems
Publicado em outubro, 31 2022 - 5:33 AM
Found the solution. By default webpack-dev-server runs the application on localhost:<port>. To change it you can run the webpack-dev-server using this command (by passing the --host option):

webpack-dev-server --port 3000 --hot --host 0.0.0.0

0.0.0.0 binds to all hosts.

I changed my package.json and now it's look like:

{
"name": "flux-jenezis",
"version": "1.0.0",
"description": "Flux realisatoin usign egghead guide",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --host 0.0.0.0"
},
"keywords": [
"flux",
"react"
],
"author": "jenezis",
"license": "ISC",
"dependencies": {
"flux": "^2.1.1",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-router": "^2.4.0"
},
"devDependencies": {
"babel-core": "^6.7.7",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0"
}
}
My Virtualbox VM is a linux VM with an apache web server on it. I use Vagrant to easily spin up my VM with a config file, Vagrant calls these a 'Vagrantfile'. In the 'Vagrantfile' you can specify ports you want forwarded between the guest machine (your VM) and the host machine (your actual OS).

This looks something like this:

config.vm.network "forwarded_port", guest: 3000, host: 3000

When the VM spins up , that port(s) will now be accessible from your guest machine on your host machine. In other words, if your webpack config looks like this:

devServer: {
host: '0.0.0.0',
port: 3000
}
You should now be able to visit http://0.0.0.0:3000 from your browser on your host machine.

Note: If you're using Virtualbox but not Vagrant and you still need help with port-forward, visit this article for some good tips: https://blog.codecentric.de/en/2017/08/fix-webpack-watch-virtualbox/ https://omegle.ws