diff --git a/Dockerfile b/Dockerfile index 6e7cc65..459c014 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,7 @@ LABEL \ org.opencontainers.image.licenses="MIT" WORKDIR /app COPY --from=build /app /app -ENV HTTP_PORT=8080 HTTPS_PORT=8443 +ENV HTTP_PORT=8080 HTTPS_PORT=8443 HTTP_HOST=0.0.0.0 HTTPS_HOST=0.0.0.0 EXPOSE $HTTP_PORT $HTTPS_PORT USER 1000 CMD ["node", "./index.js"] diff --git a/index.js b/index.js index eba6fba..6aa265a 100644 --- a/index.js +++ b/index.js @@ -212,9 +212,9 @@ if(process.env.MTLS_ENABLE){ } } -var httpServer = http.createServer(httpOpts, app).listen(process.env.HTTP_PORT || 8080); -var httpsServer = https.createServer(httpsOpts,app).listen(process.env.HTTPS_PORT || 8443); -console.log(`Listening on ports ${process.env.HTTP_PORT || 8080} for http, and ${process.env.HTTPS_PORT || 8443} for https.`); +var httpServer = http.createServer(httpOpts, app).listen(process.env.HTTP_PORT || 8080, process.env.HTTP_HOST || '0.0.0.0'); +var httpsServer = https.createServer(httpsOpts,app).listen(process.env.HTTPS_PORT || 8443, process.env.HTTPS_HOST || '0.0.0.0'); +console.log(`Listening on ${process.env.HTTP_HOST || '0.0.0.0'}:${process.env.HTTP_PORT || 8080} for http, and ${process.env.HTTPS_HOST || '0.0.0.0'}:${process.env.HTTPS_PORT || 8443} for https.`); let calledClose = false; diff --git a/tests.sh b/tests.sh index 1262fe7..a1af779 100755 --- a/tests.sh +++ b/tests.sh @@ -653,6 +653,22 @@ message " Stop containers " docker stop http-echo-tests sleep 5 +message " Start container with different hostnames " +docker run -d --rm -e HTTP_HOST=127.0.0.1 -e HTTPS_HOST=127.0.0.1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing +sleep 5 +REQUEST=$(curl -s -k http://127.0.0.1:8080/hello-world) +if [[ "$REQUEST" == "Hello World" ]] +then + passed "Different hostnames test passed." +else + failed "Different hostnames test failed." + exit 1 +fi + +message " Stop containers " +docker stop http-echo-tests +sleep 5 + popd rm -rf testarea message "DONE"