【问题标题】:Route parameters don't work with express and heroku路由参数不适用于 express 和 heroku
【发布时间】:2021-10-20 21:41:31
【问题描述】:

我在 heroku 上有一个快速服务器,但不知何故我无法使参数化的 get 请求正常工作。

var app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded());

const port = process.env.PORT || 3000;

app.listen(port, () => 
 console.log("Server running on port:" + port));

 app.get("/", (req, res, next) => {
      res.send("Hello")
  });


  app.get("/get-checkout/:contract/:nft-id", (req, res, next) => {
   res.send("checkout")
  });

第一个 get 有效,但第二个导致“Cannot GET”错误,每当我尝试 get 时

https://myserver.herokuapp.com/get-checkout/test/test

我查看了很多示例,但我无法弄清楚我做错了什么。

【问题讨论】:

    标签: express heroku get


    【解决方案1】:

    看来,你不能在参数名称中使用“-”符号。考虑到您不能在变量名中使用“-”,这是有道理的。

    所以这会起作用:

    app.get("/get-checkout/:contract/:nftid", (req, res, next) => {
    

    【讨论】:

      猜你喜欢
      • 2017-08-29
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-19
      • 2022-01-24
      相关资源
      最近更新 更多