Change handler expressjs

时间:2016-09-01 06:26:16

标签: javascript node.js express

I had this idea to change the handler of a rest request in express on the fly without restarting the server. My idea was something like that

app.use("/test", (req,res) => {
  res.json("hello!");
})
app.use("/test", (req,res) => {
  res.json("bye!");
})

But it doesn't seem to work, because I always get the answer back from the first one. I think express just appends the second one to the same route, but how can I replace them.

1 个答案:

答案 0 :(得分:0)

简单的方法是在处理程序周围构建一个包装器。

GetRenderingHtml