0

I need to be able to bind my linux container 'npm start' address to 10.XX.XX.XX so I may be able to view from my host box. Both host and container are Ubuntu. Host is Ubuntu 18 and container is 16 Xenial.

I am currently following a netlify-cms victor-hugo tutorial. My setup is on a linux container running Ubuntu 16 Xenial. npm works however, I am unable to figure out how to bind the address to the linux container ip address.

I can usually figure this out as servers will usually have a -b flag, or some kind of binding or host setting to use or something similar but I can't figure this one out. I've done modifications to the package.json file and some online examples use http-server but my setup with netlify-cms and victor-hugo uses "start":"run-p start:**". A search for run-p examples come up blank.

I have very little experience with node.js and npm. here is a partial of the package.json setup

{
  "name": "victor-hugo",
  "version": "1.0.0",
  "description": "Victor Hugo is a Hugo boilerplate for creating truly epic websites!",
  "repository": "netlify/victor-hugo",
  "main": "index.js",
  "scripts": {
    "lint": "eslint src",
    "start": "run-p start:**",
    "start:hugo": "hugo -d ../dist -s site -vw",
    "start:webpack": "webpack-dev-server --config webpack.dev.js",
    "preview": "run-p preview:**",
    "preview:hugo": "npm run start:hugo -- -D -F",
    "preview:webpack": "npm run start:webpack",
    "prebuild": "rimraf dist",
    "build": "npm run build:webpack && npm run build:hugo",
    "build:preview": "npm run build:webpack && npm run build:hugo:preview",
    "build:hugo": "hugo -d ../dist -s site -v",
    "build:hugo:preview": "npm run build:hugo -- -D -F",
    "build:webpack": "cross-env NODE_ENV=production webpack --config webpack.prod.js --hot --inline"
  },
  ...
}

I need to be able to browse to 10.XX.XX.XX to view my content.

earth2jason
  • 715
  • 1
  • 9
  • 20

2 Answers2

1

In your webpack.dev.js file, there may be a section like below:

devServer: {
  ...,
  ...,
  host: '10.XX.XX.XX',
  port: 80,
}

or you can change the webpack-dev-server command to allow the host:

"start:webpack": "webpack-dev-server --config webpack.dev.js --allowed-hosts example.com",

Not sure you can use an ip address as a replacement for example.com, but worth a try.

talves
  • 13,993
  • 5
  • 40
  • 63
1

not sure if this is still of interest, but I wanted to bind the address to 0.0.0.0 (since I am running npm within a Docker container) and it worked for me by setting the --host option in start:webpack option, like so:

"start:webpack": "webpack-dev-server --config webpack.dev.js --host 0.0.0.0"

Hope this still helps someone

mgfernan
  • 783
  • 2
  • 8
  • 21