I am using Express 4.12.3 to serve out static files for a web site. I want to be able to navigate to example.com/mypage which would retrieve /mypage.html. In other words I want to be able to pull up the page without having to type in the .html extension in the URL.
My code looks like this:
var express = require('express');
var app = express();
var server = require('http').Server(app);
app.use(express.static(__dirname + '/public'));
server.listen(4000);
I can access my page in the browser while using the .html extension but get a not found when dropping the extension. Any ideas how to configure my express server to allow this?
You can set the extensions
option to include fallback file extensions to try:
app.use(express.static(__dirname + '/public', {
extensions: ['html']
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With