I had my first static site deployed at sea-lion-app-dpidq.ondigitalocean.app . Then I added a React webapp component (after following this tutorial: https://react.dev/learn/tutorial-tic-tac-toe) in the same project. DigitalOcan gave me a new HTTP route to sea-lion-app-dpidq.ondigitalocean.app/forest-visualizer but when I try to access it I get the error “Invalid Host Header”.
When deploying the React component, I did not specify any HTTP requests in anyway as I was crueless how to manually configure it. Many StackExchange websites (ex. https://stackoverflow.com/questions/43619644/i-am-getting-an-invalid-host-header-message-when-connecting-to-webpack-dev-ser) say to fix disableHostCheck, but I do not have any file that specifies the script.
Does anyone know how to fix the issue? Please also let me know if this is not enough information to debug.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey Yutaro 👋,
If you’re using webpack-dev-server locally for development, you need to configure it to allow requests from your DigitalOcean subdomain by setting allowedHosts in the Webpack configuration file.
Create or update your webpack.config.js (if it doesn’t already exist) and add the following under the devServer configuration:
module.exports = {
// ...other webpack config
devServer: {
allowedHosts: ['sea-lion-app-dpidq.ondigitalocean.app'],
},
};
This tells the dev server to accept requests from your DigitalOcean domain.
If you’re using Create React App (CRA), you may not have direct access to the webpack.config.js file. In that case, you can set the HOST environment variable to match your domain:
.env file in the root of your project (if it doesn’t exist) and include the following:
HOST=sea-lion-app-dpidq.ondigitalocean.app
Then try again.
Since you’re deploying the app on DigitalOcean, the error could also appear if you’re serving the app with Webpack’s dev server instead of a production server like Nginx. Make sure you’re using npm run build to create a production build, and then deploy the static files to DigitalOcean’s App Platform or Spaces.
npm run build
Then deploy the generated build folder instead of running it with Webpack’s development server.
That is the recommended way to serve a React app in production rather than using the development server.
As a last resort, you can disable the host check. However, this is not recommended for production environments as it weakens security. To do this with Create React App:
.env file:
DANGEROUSLY_DISABLE_HOST_CHECK=true
\— Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.