new SGAppsServerDictionary(optionsopt)
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
options |
object
|
<optional>
|
Properties
Name |
Type |
Attributes |
Default |
Description |
name |
string
|
<optional>
|
""
|
|
reverse |
boolean
|
<optional>
|
false
|
|
|
Members
_dictionary :Object.<string, Array.<RequestHandler>>
- Source:
Type:
- Source:
Type:
Methods
generatePathKey(path) → {string}
- Source:
Parameters:
Returns:
-
Type
-
string
push(path, handlers)
- Source:
Example
server.get('/', (req, res) => {
res.send('root');
})
// will match "test" "best", everything with est
server.get(/.*est/, (req, res) => {
res.send('root');
})
server.get('/:name/:surname', (req, res) => {
const { name, surname } = req.params;
res.send(`Hi ${name} ${surname}`);
})
// apply rules with regexp emulation, they are marked with "^" in the start
server.get('^/:name([a-z]+)/:age(\d+)', (req, res, next) => {
const { name, age } = req.params;
if (age < 18) {
res.send(`Hi ${name}, you are not allowed`);
} else {
next()
}
})
// apply rules with regexp emulation, they are marked with "^" in the start
server.get('^/([a-z]+)/', (req, res, next) => {
const { name, age } = req.params;
if (age < 18) {
res.send(`Hi ${name}, you are not allowed`);
} else {
next()
}
})
// add regular expression with group names
server.get('^/(?<test>[a-z]+)/', (req, res, next) => {
const { test } = req.params;
res.send(`param: ${test}`);
})
server.get('/', (req, res) => {
res.send('root');
})
Parameters:
run(request, response, server, callback)
- Source:
Parameters: