Invalid Host Header when ngrok tries to connect to React dev server

后端 未结 4 1900
走了就别回头了
走了就别回头了 2021-01-29 17:04

I\'m trying to test my React application on a mobile device. I\'m using ngrok to make my local server available to other devices and have gotten this working with a variety of o

4条回答
  •  一个人的身影
    2021-01-29 17:52

    I used this set up in a react app that works. I created a config file named configstrp.js that contains the following:

    module.exports = {
    ngrok: {
    // use the local frontend port to connect
    enabled: process.env.NODE_ENV !== 'production',
    port: process.env.PORT || 3000,
    subdomain: process.env.NGROK_SUBDOMAIN,
    authtoken: process.env.NGROK_AUTHTOKEN
    },   }
    

    Require the file in the server.

    const configstrp      = require('./config/configstrp.js');
    const ngrok = configstrp.ngrok.enabled ? require('ngrok') : null;
    

    and connect as such

    if (ngrok) {
    console.log('If nGronk')
    ngrok.connect(
        {
        addr: configstrp.ngrok.port,
        subdomain: configstrp.ngrok.subdomain,
        authtoken: configstrp.ngrok.authtoken,
        host_header:3000
      },
      (err, url) => {
        if (err) {
    
        } else {
    
        }
       }
      );
     }
    

    Do not pass a subdomain if you do not have a custom domain

提交回复
热议问题