Skip to content

Having 'index.html' file in root directory of static assets causes weird behaviors #4804

@shuaibw

Description

@shuaibw
app.js
frontend/
    index.html
    home.html

Suppose I have the above file structure in my project, and the following code in app.js.

const morgan = require('morgan');
const express = require('express');

const app = express();
app.use(express.static('frontend'));
app.use(morgan('dev'));

app.listen(3000, () => {
    console.log('Server listeing at 3000');
});

Clearly, there's not a single HTTP request handling in app.js. But if you type http://localhost:3000 in your browser, it automatically loads the index.html page for you, without logging any HTTP request. It should have displayed Cannot GET /, but it doesn't.
If you rename the index.html to any other name, say login.html, then going to http://localhost:3000 displays the message Cannot GET /, which is as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions