tanweerdev

tanweerdev

Sometimes I need to share network address of my machine with my colleague which have access to same network(same wifi). and its really useful if he can connect to my machine and perform queries/requests from their machine eg when I run a vue project, it prints:

Compiled successfully in 16911ms                                                                                                                                                          4:55:26 PM


  App running at:
  - Local:   http://localhost:8080/ 
  - Network: http://192.16*.***.**:8080/

and I can share this network address with my colleagues and they can access web app on my machine. I am wondering if I can get this network address in phoenix app. Thanks

Showing Posts 1 to 8

NobbZ

NobbZ

In development mode the application binds only to 127.0.0.1 (or ::1 on IPv6 enabled systems) if I recall correctly. This is to avoid some bad player in the network ruining your development effort by attacking your application.

In general it is considered good practice to have development on localhost only.

If you want to open this up, you have to specify the IP to bind to manually. There is nothing in phoenix what would try to autodetect what it could possibly bind to.

And thats a good thing, as a single computer can have many interfaces and each interface could have many IP addresses.

You do not want to expose an in development software on the wrong IP to the wrong network.

PS: You can totally bind to 0.0.0.0/::, but you should be aware of the consequences, and you still need to manually check your systems interfaces for the IP you want to hand to your co-workers.

tanweerdev

tanweerdev OP

Thanks @NobbZ. and I understand this as well. But if I get my inet address using ifconfig on ubuntu(I am not sure if this is different on mac or Windows), I can still connect to my server from other machines on the same network so nothing stopping me already. I just want to get that inet address from the system and on server start print it on the screen(development machine) and if I needed will share it with my colleague who is on the same network

tanweerdev

tanweerdev OP

maybe System.cmd will help me(and call ifconfig) but it should be consistent on all machines(mac, ubuntu or windows)

LostKobrakai

LostKobrakai

This is the default currently. It’s changed on master on github to localhost only however.

tanweerdev

tanweerdev OP

@LostKobrakai I dont think binding is the problem/issue here. I dont want to change binding. I want to get network address in phoenix/elixir app

LostKobrakai

LostKobrakai

Given the phoenix generators were just changed to bind to localhost only (and therefore only to a single interface) I doubt this can make it into phoenix itself. You could however alias phx.server and run a custom mix task after phoenix started doing your own logging.

tanweerdev

tanweerdev OP

This works hostname -I | awk '{print $1}' in linux. I should be abke to run this via System.cmd I guess. Hopefully its same for each OS

tanweerdev

tanweerdev OP

This is how I got it working(credit goes to):

{ip_string, 0} = System.cmd "hostname", ["-I"]
network_address = List.first String.split(ip_string)
— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews