LoginSignup
2
2

More than 1 year has passed since last update.

Androidブラウザ(実機 or エミュレータ)からローカルサーバ(localhost)にアクセスする

Posted at

はじめに

MacのPCにローカルサーバでnode.jsのアプリをnode appで実行している場合に、実機の端末からアクセスする方法です。
node.jsの場合はポートが3000がデフォルトです。

端末からアクセス

実機もPCももちろん同じネットワークに接続します。

http://localhost:3000/

このようにしてPCからであればアクセスできますが、実機やエミュレータでは、何もしないとエラーとなります。

http://127.0.0.1:3000/

これも同じくエラーです。

エミュレータと実機でアクセス方法が違います。

エミュレータの場合

http://10.0.2,2:3000/

これでアクセスできます

実機の場合

まずPCでchromeブラウザを立ち上げて下記のアドレスにアクセスします。

chrome://inspect/#devices

スクリーンショット 2021-08-18 19.02.58.png

そして、port forwardingというボタンを押します

スクリーンショット 2021-08-18 19.03.06.png

そして下記のように登録して、Enable port forwardingにチェックを入れます
ipaddress and port : localhost:3000
port : 3000

この状態にすると

http://localhost:3000/

これでアクセスできます

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2