简体   繁体   English

快速发布所有路线

[英]Express post all routes

I am working on an express project and I have a search bar in the navigation bar for the layout page (I am using jade). 我正在做一个快递项目,并且在导航栏中有一个用于布局页面的搜索栏(我使用的是玉)。 Every page will extend to the layout, and this means it will have the search bar on every page. 每个页面都将扩展到布局,这意味着它将在每个页面上都有搜索栏。 Currently, this is my code: 目前,这是我的代码:

app.post('thing', (res, req) => {
  console.log('form: ' + req.body);
}

app.post('/*', (res, req) => {
  console.log("search: " + req.body);
}

How do I make it so that the second post calls on every page, including the /thing/, as well as the first post only calling on /thing/. 如何使第二个帖子在每个页面(包括/ thing /)上调用,以及第一个帖子仅在/ thing /上调用。 Any help is appreciated! 任何帮助表示赞赏! Thanks 谢谢

I would do it by changing the second post handler to a middleware : 我可以通过将第二个后处理程序更改为中间件来实现

app.post((res, req, next) => {
  console.log("search: " + req.body);
  next();
}

app.post('thing', (res, req) => {
  console.log('form: ' + req.body);
}

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

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