使用node.js服务网页时,如何摆脱.html扩展名? [英] How to get rid of .html extension when serving webpages with node.js?
问题描述
我是node.js的初学者,并且正在使用express和ejs布局,并且我想知道在放置页面时如何摆脱.html扩展名.例如,如果我转到我的localhost:3000/about.html-可以,但是我希望它显示为/about.另外,如果有人知道如何从明示的默认设置中快速更改图标,则很难弄清楚如何更改图标.
I am a beginner with node.js and am using express with the ejs layout, and I want to know how to get rid of the .html extension when putting up a page. For example if I go to my localhost:3000/about.html - that works but I want it to show up as just /about. Also, having trouble figuring out how to change the favicon if anyone knows how to quickly change that from the express default.
任何帮助都将非常感谢.
Any help would be great thanks.
推荐答案
我知道了.我看了这篇文章呈现基本的HTML视图?,它解决了我遇到的问题.
I figured it out. I looked at this post Render basic HTML view? which solved the problem I was having.
app.engine('html', require('ejs').renderFile);
app.get('/', function(req, res){
res.render("index.html");
});
所有这些都放在app.js或您正在运行的任何文件中.
And this all goes in the app.js or whatever file you are running.
这篇关于使用node.js服务网页时,如何摆脱.html扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!