Polv
Polv

Reputation: 2208

Docker Express.js not serving static files due to redirect to HTTPS (also a problem with Fastify)

And also reproducible is this repo https://github.com/patarapolw/docker0000

I am opening http://localhost:8080 in Chrome Version 80.0.3987.163 (Official Build) (64-bit) / macOS 10.15.3 MacAir 15 inch

It gets redirected to https://localhost:8080 every time.

├── package.json
├── public
│   └── index.html
├── server.js
├── .dockerignore
└── Dockerfile
// server.js

const app = require('express')()
app.use(require('express').static(
  require('path').join(__dirname, 'public')
))
app.listen(8080, () => {
  console.log('Go to http://localhost:8080')
})
# Dockerfile

FROM node:12-alpine
RUN mkdir /app
WORKDIR /app
COPY package.json .
RUN npm i
COPY . .
CMD ["node", "server.js"]
// package.json

  "scripts": {
    "start": "docker run -p 8080:8080 express-sample",
    "build": "docker build -t express-sample ."
  },

Error message is

Must be some Chrome security...

Upvotes: 1

Views: 1051

Answers (1)

Marcos Casagrande
Marcos Casagrande

Reputation: 40404

Chrome has cached a redirect to https, you need to clear it:

  • Go to: chrome://net-internals/#hsts > Delete domain security policies
  • Enter your domain and click delete.
  • You may need to clear browser cache too: chrome://settings/clearBrowserData (Cached images and files)

As an alternative you can use another domain for developing that isn't cached, you can do that by editing /etc/hosts file and adding:

127.0.0.1 dev.foo

And then access to http://dev.foo:8080

Upvotes: 1

Related Questions