admin管理员组文章数量:1221312
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/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?
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?
Share Improve this question asked May 20, 2015 at 19:09 risingtigerrisingtiger 8791 gold badge11 silver badges21 bronze badges1 Answer
Reset to default 23You can set the extensions
option to include fallback file extensions to try:
app.use(express.static(__dirname + '/public', {
extensions: ['html']
}));
本文标签: javascriptNodeJS ExpressShow URL without using html extensionStack Overflow
版权声明:本文标题:javascript - NodeJS Express - Show URL without using html extension - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739363097a2159912.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论