LoginSignup
34
43

More than 5 years have passed since last update.

localtunnelを使ってPaypalなどの外部連携機能を開発環境で手軽にテストする

Last updated at Posted at 2015-08-13

Paypal決済など、外部サービスから開発中のアプリケーションに対するHTTP(s)の連携が必要な時に、どうやってテストしているでしょうか? 多くの場合、開発環境は手元のマシンだったり、仮想マシンの中で動いていて、インターネットから到達できない場合が多いと思います。そのような状況でも、外部サービスとの連携テストが簡単に行うための方法を紹介します。

localtunnel

手順としては非常にシンプルで

$ npm install -g localtunnel
$ lt --port 80
your url is: https://mgwwbinxja.localtunnel.me

のように実行してやると、インターネット上で https://mgwwbinxja.localtunnel.me にアクセスすると、手元マシンの http://127.0.0.1:80 に接続されるようになりました!

同じ名前を使いたい

--subdomain オプションを使うことで、同じ名前を使い続けることができます。

$ lt --port 80 --subdomain localtunnel012qiita
your url is: https://localtunnel012qiita.localtunnel.me

セキュリティに注意

この方法で公開すると、開発中のアプリケーションに対して、世界中の誰もがアクセスできるようになってしまいます。
それは好ましくないため、 Nginx or Apache で Reverse Proxy を作成し、特定のパス配下のみアクセスできるようにしておきましょう。

Apacheの場合:

Listen *:18080
NameVirtualHost *:18080
<VirtualHost *:18080>
    ServerName localtunnel.example.com
    CustomLog /var/log/httpd/access-localtunnel.log combined
    ProxyPass /something-callbacks http://127.0.0.1:80/something-callbacks
</VirtualHost>

Links

34
43
2

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
34
43