0

I can use

app.get('/:someVar/xxxxx', function(req, res) { /* etc */ });

to get someVar by req.params.someVar. However, I want both www.example.com/12345/xxxxx and www.example.com/xxxxx to go into the same app.get

How should I approach this problem?

1
  • I noticed you don't accept any of the answers to your questions. It's bad etiquette on stackoverflow to ask a question and "abandon" it. You should go through your questions and accept whichever answer (if it exists) helped you to solve your problem. It's a form of closure, if you will. Commented Jun 5, 2015 at 8:49

2 Answers 2

1

Assign function to variable

var yourFunction = function (req, res) {
...
}

And you can use it afterwards as parameter passed to app.get()

app.get('/:someVar/xxxxx', yourFunction);
app.get('/xxxxx', yourFunction);
Sign up to request clarification or add additional context in comments.

1 Comment

talk about FGITW
1

Don't repeat yourself. Pass an array to express.js's route method:

app.route(["/12345/xxxxx", "/xxxxx"])
   .get(function (req, res) { /* etc */ })

see app.route & app.get

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.