Home > Net >  Route parameters don't work with express and heroku
Route parameters don't work with express and heroku

Time:10-23

I have an express server on heroku and somehow I can't make the parametrized get request working.

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")
  });

The first get works, but the second results in a "Cannot GET" error, whenever I try get

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

I have looked at a lot of examples and I can't figure out what I am doing wrong.

CodePudding user response:

Well, it appears, you can't use "-" symbol in the names of the parameters. Which makes sense considering that you can't use the "-" in the variable name.

So this will work:

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