简体   繁体   English

快递路线从哪里开始?

[英]express route beginning with?

I'm trying to create a route that begins with a question mark and I cannot get it done. 我正在尝试创建以问号开头的路线,但无法完成。 This is what I have: 这就是我所拥有的:

app.get('/?email=:e', function(req, res){
    console.log("here");
    console.log(req.body);
});

I'm trying to have the user enter something that will be 'e' and the route be '/?email='. 我正在尝试让用户输入将为'e'且路由为'/?email ='的内容。

Am I dong it correctly? 我正确吗? Is there something I am missing? 我有什么想念的吗?

well api routing doesn't allow ? 好的api路由不允许吗? in the url, because it would automatically be resolved as a query parameter. 在网址中输入,因为它将自动作为查询参数解析。

If you are trying something like http://localhost:3000/?email=abc@example.com then the function should be 如果您尝试使用http://localhost:3000/?email=abc@example.com之类的功能,则该功能应为

app.get('/', function(req, res){
    console.log("email is " + req.query.email);
});

If you want to send email in your path something like http://localhost:3000/email/abc@example.com then you may try 如果您想在路径中发送电子邮件,例如http://localhost:3000/email/abc@example.com则可以尝试

app.get('/email/:email', function(req, res){
    console.log("email is " + req.params.email);
});

or email path with e query string something like http://localhost:3000/email?e=abc@example.com 或带有e查询字符串的email路径, e http://localhost:3000/email?e=abc@example.com

app.get('/email', function(req, res){
    console.log("email is " + req.query.e);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM