Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do browsers automatically request index.html when connecting to a server?

I'm creating a web server using Node & Express. I've set up express.static on my express instance to point to a folder called public that contains index.html, but I've yet to set up any routes.

var express = require("express");
var app = express();
app.use(express.static("public"));

However, when I connect to the server with a browser I receive index.html even though I haven't specifically requested it in the url. Why is this? Does the browser automatically request index.html if no path is set, or is this some sort of default route in Express or Node?

like image 217
irishjauntingcar Avatar asked Apr 29 '26 01:04

irishjauntingcar


1 Answers

It's not the browser that looks for index.html if no path is set, it's actually what's sent back from the server. Typically by default, servers are configured to give back an index.html or index.php if no page is explicitly requested. Depending on the server, you can have whatever page you want get sent back to the client if no path is specified by editing the configuration file(s).

like image 116
Retro Gamer Avatar answered May 01 '26 17:05

Retro Gamer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!