快速发送文件和重定向 URL
Express sendfile and redirect url
我有一堆中间件。在第一个app.use
,我测试该过程是否受到胁迫,如果是这样,我希望它只发送静态/index.html
文件并将用户的浏览器重定向到"/#" + req.url
。
例如:
app.set("port", PORT)
//etc
app.use(function(req, res, next) {
if (something)
res.sendfile('/public/index.html', { root: __dirname + '/..' })
// also, redirect the user to '/#' + req.url
else
next()
});
// a ton more middleware that deals with the main site
app.use(express.static(...))
现在,它只是将索引.html发送到他们所在的任何网址。如何将它们重定向到"/"并提供索引.html而不会弄乱任何未来的中间件。
不确定我是否正确理解,但请尝试以下操作:
app.use(function(req, res, next) {
if (something && req.path !== '/')
return res.redirect('/');
next();
});
app.get('/', function(req, res, next) {
if (something)
return res.sendfile('/public/index.html', { root: __dirname + '/..' });
next();
});
app.use(express.static(...));
相关文章:
- safari扩展中的重定向url
- 将重定向URL链接添加到JS函数
- 使用phonegap重定向URL
- 在php中htaccess重定向url后,无法加载css和js
- 如何在重定向 URL 的标头中拦截和获取位置
- 如何使用javascript查询重定向url
- 如何使用javascript获取重定向url
- 重定向(URl)提供控制器视图 URI模式
- 带有Authorization标头的JavaScript重定向URL
- 从数组随机重定向URL
- 在重定向URL上使用HubSpot表单数据
- 如何在 Javascript 或 jQuery 中重定向 URL
- 快速发送文件和重定向 URL
- 使用javascript基于登录用户重定向URL链接
- 如何使用javascript完全重定向URL
- JavaScript var 值,重定向 URL 为空
- 如何在WordPress中即时重定向URL
- 在选项卡更改时重定向 URL
- 已更新:从另一个页面重定向 url 传递参数
- 从页面文档文本重定向 URL