Skip to content

Technique : Simplification de l'accès au serveur de développement local depuis d'autres appareils#4988

Merged
dejafait merged 3 commits intomasterfrom
dejafait/localhost_remote_access
Oct 28, 2024
Merged

Technique : Simplification de l'accès au serveur de développement local depuis d'autres appareils#4988
dejafait merged 3 commits intomasterfrom
dejafait/localhost_remote_access

Conversation

@dejafait
Copy link
Contributor

@dejafait dejafait commented Oct 25, 2024

🤔 Pourquoi ?

Si un développeur fait tourner son local dev sur une machine A (ex : un laptop) et veut y accéder depuis une machine B (ex : une tablette), il ne peut jusqu'ici pas le faire proprement (nécessité de modifier dev.py qui est versionné) et il manque la documentation de comment y parvenir.

@dejafait dejafait added no-changelog Ne doit pas figurer dans le journal des changements. tech labels Oct 25, 2024
@dejafait dejafait self-assigned this Oct 25, 2024
@dejafait dejafait force-pushed the dejafait/localhost_remote_access branch from 4674748 to d7773d8 Compare October 25, 2024 09:35
@dejafait dejafait requested a review from tonial October 25, 2024 09:37
@dejafait dejafait removed the no-changelog Ne doit pas figurer dans le journal des changements. label Oct 25, 2024

ALLOWED_HOSTS = ["localhost", "127.0.0.1", "192.168.0.1", "0.0.0.0"]
if os.getenv("CUSTOM_ALLOWED_HOST"):
ALLOWED_HOSTS.append(os.getenv("CUSTOM_ALLOWED_HOST"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

est-ce qu'on ne pourrait pas directement ajouter os.getenv("RUNSERVER_DOMAIN").split(":")[0] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah bah oui c'est une très bonne idée ça ! 👍

En supposant que votre serveur ait pour IP `100.1.2.3`, ajoutez ces lignes à votre `.envrc` :

```
export RUNSERVER_DOMAIN=100.1.2.3:8000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est géré où , ça ne fonctionne pas chez moi 🤔 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est une variable optionnelle utilisée dans le make runserver :

runserver: $(VIRTUAL_ENV)
	python manage.py runserver $(RUNSERVER_DOMAIN)

Si ça ne fonctionne pas chez toi, tu peux confirmer que tu utilises bien direnv ? Et que tu as fait un direnv reload pour prendre en compte la modification de ton .envrc ?

Copy link
Contributor

@tonial tonial Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups, j'avais en effet oublié de recharger (j'utilise direnv allow d'ailleurs, pas sur de ce qui change par rapport à reload mais les 2 fonctionnent)
Ça fonctionne bien, et du coup j'aurai tendance à "écouter" RUNSERVER_DOMAIN s'il existe pour remplir ALLOWED_HOSTS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il faut peut-être aussi un direnv allow. Dans le terminal tu peux vérifier immédiatemment si la variable est chargée correctement via un echo $RUNSERVER_DOMAIN.

@dejafait dejafait requested a review from tonial October 28, 2024 09:32
@dejafait dejafait added this pull request to the merge queue Oct 28, 2024
Merged via the queue into master with commit 2e55a6d Oct 28, 2024
@dejafait dejafait deleted the dejafait/localhost_remote_access branch October 28, 2024 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants