如何将Express路由别名设置为html文件? [英] How to set Express route alias to html file?

查看:70
本文介绍了如何将Express路由别名设置为html文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用一些更好的url端点来提供一些静态文件.

I'm trying to serve some static file with a nicer url endpoints.

例如,/home将投放/public/home.html.

我可能可以在路由配置中使用res.sendfile(),但是sendfile不会在生产模式下缓存文件输出,因此我不太确定这是否是一个好的解决方案.

I can probably use res.sendfile() in the route config, but sendfile will not cache the file output in production mode so I am not too sure if this is a good solution.

如何设置路由以充当HTML文件的别名?

How do I set routes to act like an alias to a html file?

推荐答案

尝试一下.

var express = require('express');
var app =express.createServer();
// ------
app.get('/home', function(req,res){
 res.sendfile(__dirname + '/public/home.html');
}); 

这篇关于如何将Express路由别名设置为html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆