9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WebpackDevServer で建てたサーバーが ngrok から見れない時

Last updated at Posted at 2017-09-19

問題

WebpackDevServerを何もせずに叩くとlocalhost:8080でサーバーが建ちます。そして、そのポートをngrokで指定したら普通に見れそうなんですが、「Invalid Host Header」と怒られ見れません。

localhost:8080 を建てる

webpack-dev-server

localhost:8080 を外部に xxxxxxxx.ngrok.io というホストで公開

ngrok http 8080

>
> ![「Invalid Host Header」と怒られる](https://qiita-image-store.s3.amazonaws.com/0/84144/2c498764-04f7-4e5a-94ee-1f853b18b592.png)

## 解決

`devServer.public`を設定する必要があります。

`webpack.config.js`をこんな感じに設定するか、

```js
{
  // ...
  devServer: {
    public: xxxxxxxx.ngrok.io,
  }
  // ...
}

cliの--publicフラグで指定してサーバーを建てます。

webpack-dev-server --public xxxxxxxx.ngrok.io

こんなログが出てれば多分OKです。

Project is running at http://xxxxxxxx.ngrok.io/

localtunnelとかも同じです。

9
3
1

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
9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?