I have a simple node js/express application with a route that sends an HTML file in the public folder to the user like
res.sendFile(path.resolve('public/sample.html'));
This HTML file uses script and link to load some resources in the same folder. So no external resource links (All resources are hosted on the same folder locally).
HTML sample:
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/sample.css" rel="stylesheet">
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<div>SAMPLE SITE</div>
<script src="scripts/socket.io.js"></script>
<script src="scripts/jquery-3.6.0.slim.min.js"></script>
<script src="scripts/sample-connect.js"></script>
</body>
This express server is running on docker-compose with configuration like this:
version: '3.8'
services:
app-server:
container_name: sample-server
image: sampleregistery.azurecr.io/sample-server
stdin_open: true
depends_on:
- a-server
- b-server
- c-websocket-server
restart: always
build: app-server
domainname: "sample-service"
ports:
- 3003:3003
networks:
- sample-app
deploy:
resources:
limits:
cpus: '0.5'
# memory: 4.1
reservations:
cpus: '0.2'
# memory: 2.1
env_file:
- sample.env
environment:
- PORT=${PORT:-3003}
- IO_ORIGIN_WHITELIST=${IO_ORIGIN_WHITELIST:-http://localhost:8080,http://localhost:80}
- FRAME_ACCESS_WHITELIST=${FRAME_ACCESS_WHITELIST:-'self',http://localhost:8080,http://localhost:80}
No issues with the docker-compose spinning up instances.
I have deployed the image alongside other images to azure container registries. I have also spun up container instances from these images. Everything works fine.
The Issue is:
An FQDN is autogenerated by azure for the container group as http://sample-service.centralus.azurecontainer.io and the express server can be accessed with the port '3003'. When I access the website on the browser, the resources are being loaded over HTTPS instead of HTTP since the requested address is in HTTP (there is no attached SSL Certificate to the server). This brought the error on the website as Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR. I noticed the site is accessing all the resources via HTTPS.
PS: This runs fine on localhost without it loading resources via HTTPS, obviously.
I have searched to see if this issue is from docker or azure container instances but I am not able to get any solution.
Question: How can I prevent resources from being accessed on another protocol (in this case, HTTPS) when the site is loaded on HTTP? Docker and Azure were mentioned here because I have only encountered this using Azure Containers.
Update 1: I have also changed the relative paths on the HTML file to an absolute one. Source code shows HTTP address but resource request still uses HTTPS. Issue Still Persists.