U
U
Umid2017-01-23 10:46:39
Node.js
Umid, 2017-01-23 10:46:39

What are the mappings in express?

The route path below maps acd to abcd.
app.get('/ab?cd', function(req, res) {
res.send('ab?cd');
});
This route path matches abcd, abbcd, abbbcd, and so on.
app.get('/ab+cd', function(req, res) {
res.send('ab+cd');
});
This route path matches abcd, abxcd, abRABDOMcd, ab123cd, and so on.
app.get('/ab*cd', function(req, res) {
res.send('ab*cd');
});
This route path maps /abe and /abcde.
app.get('/ab(cd)?e', function(req, res) {
res.send('ab(cd)?e');
});
I can not understand what kind of comparisons, and what are they for?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2017-01-23
@DarCKoder

This is standard routing. You follow a URL like mysite.com/abe or mysite.com/abcde , what will the server give you? That's right, what you have specified inside the "comparable" route, in the case of this example, this is your last case:

app.get('/ab(cd)?e', function(req, res) {
res.send('ab(cd)?e'); // здесь может быть что-нибудь, например: покажи страницу с такой-то картинкой
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question