斜杠被添加到快递服务器中的URL上 [英] Trailing slash gets appended to url in express server

查看:73
本文介绍了斜杠被添加到快递服务器中的URL上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用特定的url路由时,我遇到了快递服务器的问题.如果我在网址中自动使用单词"bind",则会在其后附加一个"/".但是我尝试过的其他URL并没有发生.

I am facing an issue with express server when I am trying to use a specific url route. If I use the word 'bind' for my url automatically a '/' gets appended to it. But it is not happening with other urls that I tried.

请参阅示例server.js代码

Please see the sample server.js code

var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');
});

app.get('/abcd', function (req, res) {
  res.send('abcd');
});


app.get('/bind', function (req, res) {
  res.send('bind');
});

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});

在浏览器中呈现的结果:

Results rendered in browser:

任何原因吗?预先感谢您的帮助.

Any reason for this?. Thanks in advance for any help.

更新:有趣的是,此问题仅发生在Google chrome中,而不发生在IE或Firefox中.因此可能是Chrome特有的问题.

UPDATE : Interestingly,this issue is happening in Google chrome only, not in IE or Firefox. So might be a Chrome specific issue.

推荐答案

尝试启用strict routing.并检查是否有错误,对您有帮助.

Try enabling strict routing. And check for errors, that should help you.

var app = express();

app.enable('strict routing'); 

这篇关于斜杠被添加到快递服务器中的URL上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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