Skip to content

Commit 6723a97

Browse files
committed
Adding host as a configurable variable
1 parent 92d7fb1 commit 6723a97

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LABEL \
2929
org.opencontainers.image.licenses="MIT"
3030
WORKDIR /app
3131
COPY --from=build /app /app
32-
ENV HTTP_PORT=8080 HTTPS_PORT=8443
32+
ENV HTTP_PORT=8080 HTTPS_PORT=8443 HTTP_HOST=0.0.0.0 HTTPS_HOST=0.0.0.0
3333
EXPOSE $HTTP_PORT $HTTPS_PORT
3434
USER 1000
3535
CMD ["node", "./index.js"]

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ if(process.env.MTLS_ENABLE){
212212
}
213213
}
214214

215-
var httpServer = http.createServer(httpOpts, app).listen(process.env.HTTP_PORT || 8080);
216-
var httpsServer = https.createServer(httpsOpts,app).listen(process.env.HTTPS_PORT || 8443);
217-
console.log(`Listening on ports ${process.env.HTTP_PORT || 8080} for http, and ${process.env.HTTPS_PORT || 8443} for https.`);
215+
var httpServer = http.createServer(httpOpts, app).listen(process.env.HTTP_PORT || 8080, process.env.HTTP_HOST || '0.0.0.0');
216+
var httpsServer = https.createServer(httpsOpts,app).listen(process.env.HTTPS_PORT || 8443, process.env.HTTPS_HOST || '0.0.0.0');
217+
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.`);
218218

219219
let calledClose = false;
220220

tests.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,22 @@ message " Stop containers "
653653
docker stop http-echo-tests
654654
sleep 5
655655

656+
message " Start container with different hostnames "
657+
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
658+
sleep 5
659+
REQUEST=$(curl -s -k http://127.0.0.1:8080/hello-world)
660+
if [[ "$REQUEST" == "Hello World" ]]
661+
then
662+
passed "Different hostnames test passed."
663+
else
664+
failed "Different hostnames test failed."
665+
exit 1
666+
fi
667+
668+
message " Stop containers "
669+
docker stop http-echo-tests
670+
sleep 5
671+
656672
popd
657673
rm -rf testarea
658674
message "DONE"

0 commit comments

Comments
 (0)